‪TYPO3CMS  11.5
FlexFormProcessor.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
7 /*
8  * This file is part of the TYPO3 CMS project.
9  *
10  * It is free software; you can redistribute it and/or modify it under
11  * the terms of the GNU General Public License, either version 2
12  * of the License, or any later version.
13  *
14  * For the full copyright and license information, please read the
15  * LICENSE.txt file that was distributed with this source code.
16  *
17  * The TYPO3 project - inspiring people to share!
18  */
19 
23 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
25 
49 {
57  public function ‪process(
58  ContentObjectRenderer $cObj,
59  array $contentObjectConfiguration,
60  array $processorConfiguration,
61  array $processedData
62  ): array {
63  // The field name to process
64  $fieldName = $cObj->stdWrapValue('fieldName', $processorConfiguration, 'pi_flexform');
65 
66  if (!isset($processedData['data'][$fieldName])) {
67  return $processedData;
68  }
69 
70  // Process FlexForm
71  $originalValue = $processedData['data'][$fieldName];
72  if (!is_string($originalValue)) {
73  return $processedData;
74  }
75  $flexFormData = GeneralUtility::makeInstance(FlexFormService::class)
76  ->convertFlexFormContentToArray($originalValue);
77 
78  // Set the target variable
79  $targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, 'flexFormData');
80 
81  if (isset($processorConfiguration['dataProcessing.']) && is_array($processorConfiguration['dataProcessing.'])) {
82  $flexFormData = $this->‪processAdditionalDataProcessors($flexFormData, $processorConfiguration);
83  }
84 
85  $processedData[$targetVariableName] = $flexFormData;
86 
87  return $processedData;
88  }
89 
97  public function ‪processAdditionalDataProcessors(array $data, array $processorConfiguration): array
98  {
99  $contentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class);
100  $contentObjectRenderer->start([$data]);
101  return GeneralUtility::makeInstance(ContentDataProcessor::class)->process(
102  $contentObjectRenderer,
103  $processorConfiguration,
104  $data
105  );
106  }
107 }
‪TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor
Definition: ContentDataProcessor.php:26
‪TYPO3\CMS\Frontend\DataProcessing
Definition: CommaSeparatedValueProcessor.php:16
‪TYPO3\CMS\Frontend\DataProcessing\FlexFormProcessor
Definition: FlexFormProcessor.php:49
‪TYPO3\CMS\Core\Service\FlexFormService
Definition: FlexFormService.php:25
‪TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface
Definition: DataProcessorInterface.php:23
‪TYPO3\CMS\Frontend\DataProcessing\FlexFormProcessor\process
‪array process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)
Definition: FlexFormProcessor.php:57
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Frontend\DataProcessing\FlexFormProcessor\processAdditionalDataProcessors
‪array processAdditionalDataProcessors(array $data, array $processorConfiguration)
Definition: FlexFormProcessor.php:97