TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
FormFrontendController.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Form\Controller;
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
22 
29 {
30 
35 
41  public function injectFormPersistenceManager(\TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface $formPersistenceManager)
42  {
43  $this->formPersistenceManager = $formPersistenceManager;
44  }
45 
56  public function renderAction()
57  {
58  $formDefinition = [];
59  if (!empty($this->settings['persistenceIdentifier'])) {
60  $formDefinition = $this->formPersistenceManager->load($this->settings['persistenceIdentifier']);
61  $formDefinition['persistenceIdentifier'] = $this->settings['persistenceIdentifier'];
62  $formDefinition = $this->overrideByFlexFormSettings($formDefinition);
63  $formDefinition = $this->overrideByTypoScriptSettings($formDefinition);
64  }
65  $this->view->assign('formConfiguration', $formDefinition);
66  }
67 
75  public function performAction()
76  {
77  $this->forward('render');
78  }
79 
87  protected function overrideByFlexFormSettings(array $formDefinition): array
88  {
89  if (isset($formDefinition['finishers'])) {
90  foreach ($formDefinition['finishers'] as &$finisherValue) {
91  $finisherIdentifier = $finisherValue['identifier'];
92  if ($this->settings['overrideFinishers'] && isset($this->settings['finishers'][$finisherIdentifier])) {
93  $prototypeName = isset($formDefinition['prototypeName']) ? $formDefinition['prototypeName'] : 'standard';
94  $configurationService = $this->objectManager->get(ConfigurationService::class);
95  $prototypeConfiguration = $configurationService->getPrototypeConfiguration($prototypeName);
96 
97  foreach ($finisherValue['options'] as $optionKey => $optionValue) {
98  // If a previous overriden finisher property is excluded at some time
99  // it is still present in the flexform database row.
100  // To avoid a override from the time the property is excluded, this check is needed
101  if (!isset($prototypeConfiguration['finishersDefinition'][$finisherIdentifier]['FormEngine']['elements'][$optionKey])) {
102  continue;
103  }
104  if (isset($this->settings['finishers'][$finisherIdentifier][$optionKey])) {
105  $finisherValue['options'][$optionKey] = $this->settings['finishers'][$finisherIdentifier][$optionKey];
106  }
107  }
108  }
109  }
110  }
111  return $formDefinition;
112  }
113 
123  protected function overrideByTypoScriptSettings(array $formDefinition): array
124  {
125  if (
126  isset($this->settings['formDefinitionOverrides'][$formDefinition['identifier']])
127  && !empty($this->settings['formDefinitionOverrides'][$formDefinition['identifier']])
128  ) {
130  $formDefinition,
131  $this->settings['formDefinitionOverrides'][$formDefinition['identifier']]
132  );
133  $formDefinition = $this->objectManager->get(TypoScriptService::class)
134  ->resolvePossibleTypoScriptConfiguration($formDefinition);
135  }
136  return $formDefinition;
137  }
138 }
forward($actionName, $controllerName=null, $extensionName=null, array $arguments=null)
injectFormPersistenceManager(\TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface $formPersistenceManager)
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)