‪TYPO3CMS  ‪main
TypeFile.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' => 'file',
40  ],
41  ],
42  ];
43 
50  public function ‪generate(array $data): string
51  {
53  $recordFinder = GeneralUtility::makeInstance(RecordFinder::class);
54  $demoImages = $recordFinder->findDemoFileObjects();
55  $recordData = [];
56  foreach ($demoImages as $demoImage) {
57  $newId = ‪StringUtility::getUniqueId('NEW');
58  $recordData['sys_file_reference'][$newId] = [
59  'table_local' => 'sys_file',
60  'uid_local' => $demoImage->getUid(),
61  'uid_foreign' => $data['fieldValues']['uid'],
62  'tablenames' => $data['tableName'],
63  'fieldname' => $data['fieldName'],
64  'pid' => $data['fieldValues']['pid'],
65  ];
66  }
67  if (!empty($recordData)) {
68  // Populate page tree via recordDataHandler
69  $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
70  $dataHandler->enableLogging = false;
71  $dataHandler->start($recordData, []);
72  $dataHandler->process_datamap();
73  }
74  return (string)count($demoImages);
75  }
76 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:94
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeFile
Definition: TypeFile.php:32
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\AbstractFieldGenerator
Definition: AbstractFieldGenerator.php:29
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeFile\generate
‪string generate(array $data)
Definition: TypeFile.php:49
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeFile\$matchArray
‪array $matchArray
Definition: TypeFile.php:35
‪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\Core\Utility\StringUtility\getUniqueId
‪static getUniqueId(string $prefix='')
Definition: StringUtility.php:57