‪TYPO3CMS  ‪main
RecordData.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 
21 
27 final class ‪RecordData
28 {
37  public function ‪generate(string $tableName, array $fieldValues): array
38  {
39  ‪$tca = ‪$GLOBALS['TCA'][$tableName];
41  $resolver = GeneralUtility::makeInstance(FieldGeneratorResolver::class);
42  foreach (‪$tca['columns'] as $fieldName => $fieldConfig) {
43  // Generate only if there is no value set, yet
44  if (isset($fieldValues[$fieldName])) {
45  continue;
46  }
47  $data = [
48  'tableName' => $tableName,
49  'fieldName' => $fieldName,
50  'fieldConfig' => $fieldConfig,
51  'fieldValues' => $fieldValues,
52  ];
53  try {
54  $generator = $resolver->resolve($data);
55  $fieldValues[$fieldName] = $generator->generate($data);
56  } catch (‪GeneratorNotFoundException $e) {
57  // No op if no matching generator was found
58  }
59  }
60  return $fieldValues;
61  }
62 }
‪TYPO3\CMS\Styleguide\TcaDataGenerator\GeneratorNotFoundException
Definition: GeneratorNotFoundException.php:25
‪TYPO3\CMS\Styleguide\TcaDataGenerator
Definition: AbstractGenerator.php:18
‪TYPO3\CMS\Styleguide\TcaDataGenerator\RecordData\generate
‪array generate(string $tableName, array $fieldValues)
Definition: RecordData.php:37
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪$tca
‪$tca
Definition: sys_file_metadata.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Styleguide\TcaDataGenerator\RecordData
Definition: RecordData.php:28