‪TYPO3CMS  9.5
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 
29 
37 {
38 
43 
48  public function ‪injectFormPersistenceManager(\‪TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface ‪$formPersistenceManager)
49  {
50  $this->formPersistenceManager = ‪$formPersistenceManager;
51  }
52 
62  public function ‪renderAction()
63  {
64  $formDefinition = [];
65  if (!empty($this->settings['persistenceIdentifier'])) {
66  $formDefinition = $this->formPersistenceManager->load($this->settings['persistenceIdentifier']);
67  $formDefinition['persistenceIdentifier'] = $this->settings['persistenceIdentifier'];
68  $formDefinition = $this->‪overrideByTypoScriptSettings($formDefinition);
69  $formDefinition = $this->‪overrideByFlexFormSettings($formDefinition);
70  $formDefinition = ‪ArrayUtility::setValueByPath($formDefinition, 'renderingOptions._originalIdentifier', $formDefinition['identifier'], '.');
71  $formDefinition['identifier'] .= '-' . $this->configurationManager->getContentObject()->data['uid'];
72  }
73  $this->view->assign('formConfiguration', $formDefinition);
74  }
75 
82  public function ‪performAction()
83  {
84  $this->‪forward('render');
85  }
86 
94  protected function ‪overrideByFlexFormSettings(array $formDefinition): array
95  {
96  $flexFormData = GeneralUtility::xml2array($this->configurationManager->getContentObject()->data['pi_flexform'] ?? '');
97 
98  if (!is_array($flexFormData)) {
99  return $formDefinition;
100  }
101 
102  if (isset($formDefinition['finishers'])) {
103  $prototypeName = $formDefinition['prototypeName'] ?? 'standard';
104  $configurationService = $this->objectManager->get(ConfigurationService::class);
105  $prototypeConfiguration = $configurationService->getPrototypeConfiguration($prototypeName);
106 
107  foreach ($formDefinition['finishers'] as $index => $formFinisherDefinition) {
108  $finisherIdentifier = $formFinisherDefinition['identifier'];
109 
110  $sheetIdentifier = $this->‪getFlexformSheetIdentifier($formDefinition, $prototypeName, $finisherIdentifier);
111  $flexFormSheetSettings = $this->‪getFlexFormSettingsFromSheet($flexFormData, $sheetIdentifier);
112 
113  if ($this->settings['overrideFinishers'] && isset($flexFormSheetSettings['finishers'][$finisherIdentifier])) {
114  $prototypeFinisherDefinition = $prototypeConfiguration['finishersDefinition'][$finisherIdentifier] ?? [];
115  $converterDto = GeneralUtility::makeInstance(
116  FlexFormFinisherOverridesConverterDto::class,
117  $formFinisherDefinition,
118  $finisherIdentifier,
119  $flexFormSheetSettings
120  );
121 
122  // Iterate over all `TYPO3.CMS.Form.prototypes.<prototypeName>.finishersDefinition.<finisherIdentifier>.FormEngine.elements` values
123  GeneralUtility::makeInstance(ArrayProcessor::class, $prototypeFinisherDefinition['FormEngine']['elements'])->forEach(
124  GeneralUtility::makeInstance(
125  ArrayProcessing::class,
126  'modifyFinisherOptionsFromFlexFormOverrides',
127  '^(.*)\.config\.type$',
128  GeneralUtility::makeInstance(FinisherOptionsFlexFormOverridesConverter::class, $converterDto)
129  )
130  );
131 
132  $formDefinition['finishers'][$index] = $converterDto->getFinisherDefinition();
133  }
134  }
135  }
136  return $formDefinition;
137  }
138 
148  protected function ‪overrideByTypoScriptSettings(array $formDefinition): array
149  {
150  if (
151  isset($this->settings['formDefinitionOverrides'][$formDefinition['identifier']])
152  && !empty($this->settings['formDefinitionOverrides'][$formDefinition['identifier']])
153  ) {
155  $formDefinition,
156  $this->settings['formDefinitionOverrides'][$formDefinition['identifier']]
157  );
158  $formDefinition = $this->objectManager->get(TypoScriptService::class)
159  ->resolvePossibleTypoScriptConfiguration($formDefinition);
160  }
161  return $formDefinition;
162  }
163 
170  protected function ‪getFlexformSheetIdentifier(
171  array $formDefinition,
172  string $prototypeName,
173  string $finisherIdentifier
174  ): string {
175  return md5(
176  implode('', [
177  $formDefinition['persistenceIdentifier'],
178  $prototypeName,
179  $formDefinition['identifier'],
180  $finisherIdentifier
181  ])
182  );
183  }
184 
190  protected function ‪getFlexFormSettingsFromSheet(
191  array $flexForm,
192  string $sheetIdentifier
193  ): array {
194  $sheetData['data'] = array_filter(
195  $flexForm['data'] ?? [],
196  function ($key) use ($sheetIdentifier) {
197  return $key === $sheetIdentifier;
198  },
199  ARRAY_FILTER_USE_KEY
200  );
201 
202  if (empty($sheetData['data'])) {
203  return [];
204  }
205 
206  $flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
207  $flexFormTools = GeneralUtility::makeInstance(FlexFormTools::class);
208 
209  $sheetDataXml = $flexFormTools->flexArray2Xml($sheetData);
210  return $flexFormService->convertFlexFormContentToArray($sheetDataXml)['settings'] ?? [];
211  }
212 }
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Converters\FinisherOptionsFlexFormOverridesConverter
Definition: FinisherOptionsFlexFormOverridesConverter.php:27
‪TYPO3
‪TYPO3\CMS\Form\Controller\FormFrontendController\renderAction
‪renderAction()
Definition: FormFrontendController.php:61
‪TYPO3\CMS\Form\Controller\FormFrontendController\getFlexformSheetIdentifier
‪string getFlexformSheetIdentifier(array $formDefinition, string $prototypeName, string $finisherIdentifier)
Definition: FormFrontendController.php:169
‪TYPO3\CMS\Form\Controller
Definition: AbstractBackendController.php:3
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:614
‪TYPO3\CMS\Core\Service\FlexFormService
Definition: FlexFormService.php:21
‪TYPO3\CMS\Form\Controller\FormFrontendController\getFlexFormSettingsFromSheet
‪array getFlexFormSettingsFromSheet(array $flexForm, string $sheetIdentifier)
Definition: FormFrontendController.php:189
‪TYPO3\CMS\Form\Domain\Configuration\ArrayProcessing\ArrayProcessing
Definition: ArrayProcessing.php:25
‪TYPO3\CMS\Form\Domain\Configuration\ArrayProcessing\ArrayProcessor
Definition: ArrayProcessor.php:28
‪TYPO3\CMS\Form\Controller\FormFrontendController
Definition: FormFrontendController.php:37
‪TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools
Definition: FlexFormTools.php:36
‪TYPO3\CMS\Form\Controller\FormFrontendController\overrideByFlexFormSettings
‪array overrideByFlexFormSettings(array $formDefinition)
Definition: FormFrontendController.php:93
‪TYPO3\CMS\Form\Mvc\Configuration\TypoScriptService
Definition: TypoScriptService.php:26
‪TYPO3\CMS\Form\Controller\FormFrontendController\$formPersistenceManager
‪TYPO3 CMS Form Mvc Persistence FormPersistenceManagerInterface $formPersistenceManager
Definition: FormFrontendController.php:41
‪TYPO3\CMS\Form\Domain\Configuration\ConfigurationService
Definition: ConfigurationService.php:49
‪TYPO3\CMS\Form\Controller\FormFrontendController\performAction
‪performAction()
Definition: FormFrontendController.php:81
‪TYPO3\CMS\Core\Utility\ArrayUtility\setValueByPath
‪static array setValueByPath(array $array, $path, $value, $delimiter='/')
Definition: ArrayUtility.php:271
‪TYPO3\CMS\Form\Controller\FormFrontendController\overrideByTypoScriptSettings
‪array overrideByTypoScriptSettings(array $formDefinition)
Definition: FormFrontendController.php:147
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:23
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Converters\FlexFormFinisherOverridesConverterDto
Definition: FlexFormFinisherOverridesConverterDto.php:22
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController
Definition: ActionController.php:31
‪TYPO3\CMS\Form\Controller\FormFrontendController\injectFormPersistenceManager
‪injectFormPersistenceManager(\TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface $formPersistenceManager)
Definition: FormFrontendController.php:47
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extbase\Mvc\Controller\AbstractController\forward
‪forward($actionName, $controllerName=null, $extensionName=null, array $arguments=null)
Definition: AbstractController.php:247