‪TYPO3CMS  ‪main
TypeGroupFal.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 
25 
32 {
36  protected ‪$matchArray = [
37  'fieldConfig' => [
38  'config' => [
39  'type' => 'group',
40  'allowed' => 'sys_file',
41  'MM' => 'sys_file_reference',
42  'MM_match_fields' => [
43  'fieldname' => 'image_fal_group',
44  ],
45  'prepend_tname' => true,
46  ],
47  ],
48  ];
49 
56  public function ‪generate(array $data): string
57  {
59  $recordFinder = GeneralUtility::makeInstance(RecordFinder::class);
60  $demoImages = $recordFinder->findDemoFileObjects();
61  $recordData = [];
62  foreach ($demoImages as $demoImage) {
63  $newId = ‪StringUtility::getUniqueId('NEW');
64  // @todo: this structure is weird, see the @todo comments in TCA definition, too!
65  $recordData['sys_file_reference'][$newId] = [
66  'table_local' => 'sys_file',
67  'uid_local' => $data['fieldValues']['uid'],
68  'uid_foreign' => $demoImage->getUid(),
69  'tablenames' => 'sys_file',
70  'fieldname' => 'image_fal_group',
71  'pid' => $data['fieldValues']['pid'],
72  ];
73  }
74  if (!empty($recordData)) {
75  // Populate page tree via recordDataHandler
76  $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
77  $dataHandler->enableLogging = false;
78  $dataHandler->start($recordData, []);
79  $dataHandler->process_datamap();
80  }
81  return (string)count($demoImages);
82  }
83 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:94
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\AbstractFieldGenerator
Definition: AbstractFieldGenerator.php:29
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeGroupFal\generate
‪string generate(array $data)
Definition: TypeGroupFal.php:55
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator
Definition: AbstractFieldGenerator.php:18
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGeneratorInterface
Definition: FieldGeneratorInterface.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:24
‪TYPO3\CMS\Styleguide\TcaDataGenerator\RecordFinder
Definition: RecordFinder.php:38
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeGroupFal\$matchArray
‪array $matchArray
Definition: TypeGroupFal.php:35
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static getUniqueId(string $prefix='')
Definition: StringUtility.php:57
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeGroupFal
Definition: TypeGroupFal.php:32