‪TYPO3CMS  ‪main
TcaFolder.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 
26 
31 {
37  public function ‪addData(array $result)
38  {
39  foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfig) {
40  if (empty($fieldConfig['config']['type']) || $fieldConfig['config']['type'] !== 'folder') {
41  continue;
42  }
43 
44  // Sanitize max items, set to 99999 if not defined
45  $result['processedTca']['columns'][$fieldName]['config']['maxitems'] = ‪MathUtility::forceIntegerInRange(
46  $fieldConfig['config']['maxitems'] ?? 0,
47  0,
48  99999
49  );
50  if ($result['processedTca']['columns'][$fieldName]['config']['maxitems'] === 0) {
51  $result['processedTca']['columns'][$fieldName]['config']['maxitems'] = 99999;
52  }
53 
54  $databaseRowFieldContent = '';
55  if (!empty($result['databaseRow'][$fieldName])) {
56  $databaseRowFieldContent = (string)$result['databaseRow'][$fieldName];
57  }
58 
59  $items = [];
60  // Simple list of folders
61  $folderList = ‪GeneralUtility::trimExplode(',', $databaseRowFieldContent, true);
62  foreach ($folderList as $folder) {
63  if (empty($folder)) {
64  continue;
65  }
66  try {
67  $folderObject = GeneralUtility::makeInstance(ResourceFactory::class)->retrieveFileOrFolderObject($folder);
68  if ($folderObject instanceof ‪Folder) {
69  $items[] = [
70  'folder' => $folder,
71  ];
72  }
74  continue;
75  }
76  }
77 
78  $result['databaseRow'][$fieldName] = $items;
79  }
80 
81  return $result;
82  }
83 }
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:38
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:42
‪TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException
Definition: ResourceDoesNotExistException.php:23
‪TYPO3\CMS\Backend\Form\FormDataProvider
Definition: AbstractDatabaseRecordProvider.php:16
‪TYPO3\CMS\Backend\Form\FormDataProviderInterface
Definition: FormDataProviderInterface.php:23
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaFolder
Definition: TcaFolder.php:31
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaFolder\addData
‪array addData(array $result)
Definition: TcaFolder.php:37
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:24
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange(mixed $theInt, int $min, int $max=2000000000, int $defaultValue=0)
Definition: MathUtility.php:34
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode(string $delim, string $string, bool $removeEmptyValues=false, int $limit=0)
Definition: GeneralUtility.php:822