‪TYPO3CMS  10.4
FormFrontendController.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
32 
40 {
41 
46 
52  {
53  $this->formPersistenceManager = ‪$formPersistenceManager;
54  }
55 
65  public function ‪renderAction()
66  {
67  $formDefinition = [];
68  if (!empty($this->settings['persistenceIdentifier'])) {
69  $formDefinition = $this->formPersistenceManager->load($this->settings['persistenceIdentifier']);
70  $formDefinition['persistenceIdentifier'] = $this->settings['persistenceIdentifier'];
71  $formDefinition = $this->‪overrideByTypoScriptSettings($formDefinition);
72  $formDefinition = $this->‪overrideByFlexFormSettings($formDefinition);
73  $formDefinition = ‪ArrayUtility::setValueByPath($formDefinition, 'renderingOptions._originalIdentifier', $formDefinition['identifier'], '.');
74  $formDefinition['identifier'] .= '-' . $this->configurationManager->getContentObject()->data['uid'];
75  }
76  $this->view->assign('formConfiguration', $formDefinition);
77  }
78 
85  public function ‪performAction()
86  {
87  $this->‪forward('render');
88  }
89 
97  protected function ‪overrideByFlexFormSettings(array $formDefinition): array
98  {
99  $flexFormData = ‪GeneralUtility::xml2array($this->configurationManager->getContentObject()->data['pi_flexform'] ?? '');
100 
101  if (!is_array($flexFormData)) {
102  return $formDefinition;
103  }
104 
105  if (isset($formDefinition['finishers'])) {
106  $prototypeName = $formDefinition['prototypeName'] ?? 'standard';
107  $configurationService = $this->objectManager->get(ConfigurationService::class);
108  $prototypeConfiguration = $configurationService->getPrototypeConfiguration($prototypeName);
109 
110  foreach ($formDefinition['finishers'] as $index => $formFinisherDefinition) {
111  $finisherIdentifier = $formFinisherDefinition['identifier'];
112 
113  $sheetIdentifier = $this->‪getFlexformSheetIdentifier($formDefinition, $prototypeName, $finisherIdentifier);
114  $flexFormSheetSettings = $this->‪getFlexFormSettingsFromSheet($flexFormData, $sheetIdentifier);
115 
116  if ($this->settings['overrideFinishers'] && isset($flexFormSheetSettings['finishers'][$finisherIdentifier])) {
117  $prototypeFinisherDefinition = $prototypeConfiguration['finishersDefinition'][$finisherIdentifier] ?? [];
118  $converterDto = GeneralUtility::makeInstance(
119  FlexFormFinisherOverridesConverterDto::class,
120  $prototypeFinisherDefinition,
121  $formFinisherDefinition,
122  $finisherIdentifier,
123  $flexFormSheetSettings
124  );
125 
126  // Iterate over all `TYPO3.CMS.Form.prototypes.<prototypeName>.finishersDefinition.<finisherIdentifier>.FormEngine.elements` values
127  GeneralUtility::makeInstance(ArrayProcessor::class, $prototypeFinisherDefinition['FormEngine']['elements'])->forEach(
128  GeneralUtility::makeInstance(
129  ArrayProcessing::class,
130  'modifyFinisherOptionsFromFlexFormOverrides',
131  '^(.*)(?:(?<!\.TCEforms)\.config\.type|\.section)$',
132  GeneralUtility::makeInstance(FinisherOptionsFlexFormOverridesConverter::class, $converterDto)
133  )
134  );
135 
136  $formDefinition['finishers'][$index] = $converterDto->getFinisherDefinition();
137  }
138  }
139  }
140  return $formDefinition;
141  }
142 
152  protected function ‪overrideByTypoScriptSettings(array $formDefinition): array
153  {
154  if (
155  isset($this->settings['formDefinitionOverrides'][$formDefinition['identifier']])
156  && !empty($this->settings['formDefinitionOverrides'][$formDefinition['identifier']])
157  ) {
158  $formDefinitionOverrides = $this->objectManager->get(TypoScriptService::class)
159  ->resolvePossibleTypoScriptConfiguration($this->settings['formDefinitionOverrides'][$formDefinition['identifier']]);
160 
162  $formDefinition,
163  $formDefinitionOverrides
164  );
165  }
166  return $formDefinition;
167  }
168 
175  protected function ‪getFlexformSheetIdentifier(
176  array $formDefinition,
177  string $prototypeName,
178  string $finisherIdentifier
179  ): string {
180  return md5(
181  implode('', [
182  $formDefinition['persistenceIdentifier'],
183  $prototypeName,
184  $formDefinition['identifier'],
185  $finisherIdentifier
186  ])
187  );
188  }
189 
195  protected function ‪getFlexFormSettingsFromSheet(
196  array $flexForm,
197  string $sheetIdentifier
198  ): array {
199  $sheetData = [];
200  $sheetData['data'] = array_filter(
201  $flexForm['data'] ?? [],
202  function ($key) use ($sheetIdentifier) {
203  return $key === $sheetIdentifier;
204  },
205  ARRAY_FILTER_USE_KEY
206  );
207 
208  if (empty($sheetData['data'])) {
209  return [];
210  }
211 
212  $flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
213  $flexFormTools = GeneralUtility::makeInstance(FlexFormTools::class);
214 
215  $sheetDataXml = $flexFormTools->flexArray2Xml($sheetData);
216  return $flexFormService->convertFlexFormContentToArray($sheetDataXml)['settings'] ?? [];
217  }
218 }
‪TYPO3\CMS\Core\Utility\GeneralUtility\xml2array
‪static mixed xml2array($string, $NSprefix='', $reportDocTag=false)
Definition: GeneralUtility.php:1531
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\forward
‪forward($actionName, $controllerName=null, $extensionName=null, array $arguments=null)
Definition: ActionController.php:815
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Converters\FinisherOptionsFlexFormOverridesConverter
Definition: FinisherOptionsFlexFormOverridesConverter.php:29
‪TYPO3\CMS\Form\Controller\FormFrontendController\renderAction
‪renderAction()
Definition: FormFrontendController.php:64
‪TYPO3\CMS\Form\Controller\FormFrontendController\getFlexformSheetIdentifier
‪string getFlexformSheetIdentifier(array $formDefinition, string $prototypeName, string $finisherIdentifier)
Definition: FormFrontendController.php:174
‪TYPO3\CMS\Form\Controller
Definition: AbstractBackendController.php:18
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:654
‪TYPO3\CMS\Core\Service\FlexFormService
Definition: FlexFormService.php:25
‪TYPO3\CMS\Form\Controller\FormFrontendController\getFlexFormSettingsFromSheet
‪array getFlexFormSettingsFromSheet(array $flexForm, string $sheetIdentifier)
Definition: FormFrontendController.php:194
‪TYPO3\CMS\Form\Domain\Configuration\ArrayProcessing\ArrayProcessing
Definition: ArrayProcessing.php:27
‪TYPO3\CMS\Form\Domain\Configuration\ArrayProcessing\ArrayProcessor
Definition: ArrayProcessor.php:30
‪TYPO3\CMS\Form\Controller\FormFrontendController
Definition: FormFrontendController.php:40
‪TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools
Definition: FlexFormTools.php:38
‪TYPO3\CMS\Form\Controller\FormFrontendController\overrideByFlexFormSettings
‪array overrideByFlexFormSettings(array $formDefinition)
Definition: FormFrontendController.php:96
‪TYPO3\CMS\Form\Mvc\Configuration\TypoScriptService
Definition: TypoScriptService.php:28
‪TYPO3\CMS\Form\Controller\FormFrontendController\$formPersistenceManager
‪TYPO3 CMS Form Mvc Persistence FormPersistenceManagerInterface $formPersistenceManager
Definition: FormFrontendController.php:44
‪TYPO3\CMS\Form\Domain\Configuration\ConfigurationService
Definition: ConfigurationService.php:51
‪TYPO3\CMS\Form\Controller\FormFrontendController\performAction
‪performAction()
Definition: FormFrontendController.php:84
‪TYPO3\CMS\Core\Utility\ArrayUtility\setValueByPath
‪static array setValueByPath(array $array, $path, $value, $delimiter='/')
Definition: ArrayUtility.php:272
‪TYPO3\CMS\Form\Controller\FormFrontendController\overrideByTypoScriptSettings
‪array overrideByTypoScriptSettings(array $formDefinition)
Definition: FormFrontendController.php:151
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Converters\FlexFormFinisherOverridesConverterDto
Definition: FlexFormFinisherOverridesConverterDto.php:24
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController
Definition: ActionController.php:55
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface
Definition: FormPersistenceManagerInterface.php:32
‪TYPO3\CMS\Form\Controller\FormFrontendController\injectFormPersistenceManager
‪injectFormPersistenceManager(FormPersistenceManagerInterface $formPersistenceManager)
Definition: FormFrontendController.php:50