‪TYPO3CMS  ‪main
FlexFormProcessor.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 
20 use Psr\Http\Message\ServerRequestInterface;
27 
63 {
71  public function ‪process(
73  array $contentObjectConfiguration,
74  array $processorConfiguration,
75  array $processedData
76  ): array {
77  // The field name to process
78  $fieldName = $cObj->‪stdWrapValue('fieldName', $processorConfiguration, 'pi_flexform');
79 
80  if (!isset($processedData['data'][$fieldName])) {
81  return $processedData;
82  }
83 
84  // Process FlexForm
85  $originalValue = $processedData['data'][$fieldName];
86  if (!is_string($originalValue)) {
87  return $processedData;
88  }
89  $flexFormData = GeneralUtility::makeInstance(FlexFormService::class)
90  ->convertFlexFormContentToArray($originalValue);
91 
92  // Process FAL references
93  if (isset($processorConfiguration['references.']) && is_array($processorConfiguration['references.'])) {
94  $this->‪processFileReferences($cObj, $flexFormData, $processorConfiguration['references.']);
95  }
96 
97  // Process additional DataProcessors
98  if (isset($processorConfiguration['dataProcessing.']) && is_array($processorConfiguration['dataProcessing.'])) {
99  // @todo: It looks as if data processors should retrieve the current request from the outside,
100  // this would avoid $cObj->getRequest() here.
101  $flexFormData = $this->‪processAdditionalDataProcessors($flexFormData, $processorConfiguration, $cObj->‪getRequest());
102  }
103 
104  // Set the target variable
105  $targetVariableName = $cObj->‪stdWrapValue('as', $processorConfiguration, 'flexFormData');
106  $processedData[$targetVariableName] = $flexFormData;
107 
108  return $processedData;
109  }
110 
114  protected function ‪processFileReferences(‪ContentObjectRenderer $cObj, array &$data, array ‪$fields): void
115  {
116  foreach (‪$fields as $key => $field) {
117  $key = rtrim($key, '.');
118 
119  if (!isset($data[$key])) {
120  continue;
121  }
122  if (is_array($field)) {
123  $this->‪processFileReferences($cObj, $data[$key], $field);
124  } else {
125  $fileCollector = GeneralUtility::makeInstance(FileCollector::class);
126  $fileCollector->addFilesFromRelation($cObj->‪getCurrentTable(), $field, $cObj->data);
127 
128  $data[$key] = $fileCollector->getFiles();
129  }
130  }
131  }
132 
136  protected function ‪processAdditionalDataProcessors(array $data, array $processorConfiguration, ServerRequestInterface $request): array
137  {
138  $contentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class);
139  $contentObjectRenderer->setRequest($request);
140  $contentObjectRenderer->start([$data], '');
141  return GeneralUtility::makeInstance(ContentDataProcessor::class)->process(
142  $contentObjectRenderer,
143  $processorConfiguration,
144  $data
145  );
146  }
147 }
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\getCurrentTable
‪string getCurrentTable()
Definition: ContentObjectRenderer.php:455
‪TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor
Definition: ContentDataProcessor.php:27
‪TYPO3\CMS\Frontend\DataProcessing
Definition: CommaSeparatedValueProcessor.php:16
‪TYPO3\CMS\Frontend\DataProcessing\FlexFormProcessor
Definition: FlexFormProcessor.php:63
‪$fields
‪$fields
Definition: pages.php:5
‪TYPO3\CMS\Frontend\Resource\FileCollector
Definition: FileCollector.php:47
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\stdWrapValue
‪string int bool null stdWrapValue($key, array $config, $defaultValue='')
Definition: ContentObjectRenderer.php:1139
‪TYPO3\CMS\Core\Service\FlexFormService
Definition: FlexFormService.php:25
‪TYPO3\CMS\Frontend\DataProcessing\FlexFormProcessor\processFileReferences
‪processFileReferences(ContentObjectRenderer $cObj, array &$data, array $fields)
Definition: FlexFormProcessor.php:114
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\getRequest
‪getRequest()
Definition: ContentObjectRenderer.php:5430
‪TYPO3\CMS\Frontend\DataProcessing\FlexFormProcessor\processAdditionalDataProcessors
‪processAdditionalDataProcessors(array $data, array $processorConfiguration, ServerRequestInterface $request)
Definition: FlexFormProcessor.php:136
‪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:71
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:102
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52