‪TYPO3CMS  ‪main
TcaFlexPrepare.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
22 
29 {
39  public function ‪addData(array $result)
40  {
41  foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfig) {
42  if (empty($fieldConfig['config']['type']) || $fieldConfig['config']['type'] !== 'flex') {
43  continue;
44  }
45  $result = $this->‪initializeDataStructure($result, $fieldName);
46  $result = $this->‪initializeDataValues($result, $fieldName);
47  }
48 
49  return $result;
50  }
51 
63  protected function ‪initializeDataStructure(array $result, $fieldName)
64  {
65  $flexFormTools = GeneralUtility::makeInstance(FlexFormTools::class);
66  if (!isset($result['processedTca']['columns'][$fieldName]['config']['dataStructureIdentifier'])) {
67  $dataStructureIdentifier = null;
68  $dataStructureArray = ['sheets' => ['sDEF' => []]];
69 
70  try {
71  $dataStructureIdentifier = $flexFormTools->getDataStructureIdentifier(
72  $result['processedTca']['columns'][$fieldName],
73  $result['tableName'],
74  $fieldName,
75  $result['databaseRow']
76  );
77  $dataStructureArray = $flexFormTools->parseDataStructureByIdentifier($dataStructureIdentifier);
79  $dataStructureIdentifier = null;
80  } finally {
81  // Add the identifier to TCA to use it later during rendering
82  $result['processedTca']['columns'][$fieldName]['config']['dataStructureIdentifier'] = $dataStructureIdentifier;
83  }
84  } else {
85  // Assume the data structure has been given from outside if the data structure identifier is already set.
86  $dataStructureArray = $result['processedTca']['columns'][$fieldName]['config']['ds'];
87  }
88  if (!isset($dataStructureArray['meta']) || !is_array($dataStructureArray['meta'])) {
89  $dataStructureArray['meta'] = [];
90  }
91  // This kicks one array depth: config['ds']['listOfDataStructures'] becomes config['ds']
92  // This also ensures the final ds can be found in 'ds', even if the DS was fetch from
93  // a record, see FlexFormTools->getDataStructureIdentifier() for details.
94  $result['processedTca']['columns'][$fieldName]['config']['ds'] = $dataStructureArray;
95  return $result;
96  }
97 
105  protected function ‪initializeDataValues(array $result, $fieldName)
106  {
107  if (!array_key_exists($fieldName, $result['databaseRow'])) {
108  $result['databaseRow'][$fieldName] = '';
109  }
110  $valueArray = [];
111  if (isset($result['databaseRow'][$fieldName])) {
112  $valueArray = $result['databaseRow'][$fieldName];
113  }
114  if (!is_array($result['databaseRow'][$fieldName])) {
115  $valueArray = ‪GeneralUtility::xml2array($result['databaseRow'][$fieldName]);
116  }
117  if (!is_array($valueArray)) {
118  $valueArray = [];
119  }
120  if (!isset($valueArray['data'])) {
121  $valueArray['data'] = [];
122  }
123  if (!isset($valueArray['meta'])) {
124  $valueArray['meta'] = [];
125  }
126  $result['databaseRow'][$fieldName] = $valueArray;
127  return $result;
128  }
129 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaFlexPrepare\initializeDataStructure
‪array initializeDataStructure(array $result, $fieldName)
Definition: TcaFlexPrepare.php:63
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaFlexPrepare
Definition: TcaFlexPrepare.php:29
‪TYPO3\CMS\Core\Configuration\FlexForm\Exception\InvalidIdentifierException
Definition: InvalidIdentifierException.php:21
‪TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools
Definition: FlexFormTools.php:40
‪TYPO3\CMS\Backend\Form\FormDataProvider
Definition: AbstractDatabaseRecordProvider.php:16
‪TYPO3\CMS\Backend\Form\FormDataProviderInterface
Definition: FormDataProviderInterface.php:23
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaFlexPrepare\addData
‪array addData(array $result)
Definition: TcaFlexPrepare.php:39
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaFlexPrepare\initializeDataValues
‪array initializeDataValues(array $result, $fieldName)
Definition: TcaFlexPrepare.php:105
‪TYPO3\CMS\Core\Utility\GeneralUtility\xml2array
‪static array string xml2array(string $string, string $NSprefix='', bool $reportDocTag=false)
Definition: GeneralUtility.php:1265