TYPO3 CMS  TYPO3_8-7
FormFrontendController.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
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 
40  public function injectFormPersistenceManager(\TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface $formPersistenceManager)
41  {
42  $this->formPersistenceManager = $formPersistenceManager;
43  }
44 
54  public function renderAction()
55  {
56  $formDefinition = [];
57  if (!empty($this->settings['persistenceIdentifier'])) {
58  $formDefinition = $this->formPersistenceManager->load($this->settings['persistenceIdentifier']);
59  $formDefinition['persistenceIdentifier'] = $this->settings['persistenceIdentifier'];
60  $formDefinition = $this->overrideByFlexFormSettings($formDefinition);
61  $formDefinition = $this->overrideByTypoScriptSettings($formDefinition);
62  }
63  $this->view->assign('formConfiguration', $formDefinition);
64  }
65 
72  public function performAction()
73  {
74  $this->forward('render');
75  }
76 
84  protected function overrideByFlexFormSettings(array $formDefinition): array
85  {
86  if (isset($formDefinition['finishers'])) {
87  foreach ($formDefinition['finishers'] as &$finisherValue) {
88  $finisherIdentifier = $finisherValue['identifier'];
89  if ($this->settings['overrideFinishers'] && isset($this->settings['finishers'][$finisherIdentifier])) {
90  $prototypeName = isset($formDefinition['prototypeName']) ? $formDefinition['prototypeName'] : 'standard';
91  $configurationService = $this->objectManager->get(ConfigurationService::class);
92  $prototypeConfiguration = $configurationService->getPrototypeConfiguration($prototypeName);
93 
94  foreach ($finisherValue['options'] as $optionKey => $optionValue) {
95  // If a previous overridden finisher property is excluded at some time
96  // it is still present in the flexform database row.
97  // To avoid a override from the time the property is excluded, this check is needed
98  if (!isset($prototypeConfiguration['finishersDefinition'][$finisherIdentifier]['FormEngine']['elements'][$optionKey])) {
99  continue;
100  }
101  if (isset($this->settings['finishers'][$finisherIdentifier][$optionKey])) {
102  $finisherValue['options'][$optionKey] = $this->settings['finishers'][$finisherIdentifier][$optionKey];
103  }
104  }
105  }
106  }
107  }
108  return $formDefinition;
109  }
110 
120  protected function overrideByTypoScriptSettings(array $formDefinition): array
121  {
122  if (
123  isset($this->settings['formDefinitionOverrides'][$formDefinition['identifier']])
124  && !empty($this->settings['formDefinitionOverrides'][$formDefinition['identifier']])
125  ) {
127  $formDefinition,
128  $this->settings['formDefinitionOverrides'][$formDefinition['identifier']]
129  );
130  $formDefinition = $this->objectManager->get(TypoScriptService::class)
131  ->resolvePossibleTypoScriptConfiguration($formDefinition);
132  }
133  return $formDefinition;
134  }
135 }
injectFormPersistenceManager(\TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface $formPersistenceManager)
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
forward($actionName, $controllerName=null, $extensionName=null, array $arguments=null)