‪TYPO3CMS  ‪main
TcaGroup.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 
20 use TYPO3\CMS\Backend\Utility\BackendUtility;
24 
29 {
35  public function ‪addData(array $result)
36  {
37  foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfig) {
38  if (empty($fieldConfig['config']['type']) || $fieldConfig['config']['type'] !== 'group') {
39  continue;
40  }
41 
42  // Sanitize max items, set to 99999 if not defined
43  $result['processedTca']['columns'][$fieldName]['config']['maxitems'] = ‪MathUtility::forceIntegerInRange(
44  $fieldConfig['config']['maxitems'] ?? 0,
45  0,
46  99999
47  );
48  if ($result['processedTca']['columns'][$fieldName]['config']['maxitems'] === 0) {
49  $result['processedTca']['columns'][$fieldName]['config']['maxitems'] = 99999;
50  }
51 
52  $databaseRowFieldContent = '';
53  if (!empty($result['databaseRow'][$fieldName])) {
54  $databaseRowFieldContent = (string)$result['databaseRow'][$fieldName];
55  }
56 
57  $items = [];
58  $sanitizedClipboardElements = [];
59  if (empty($fieldConfig['config']['allowed'])) {
60  throw new \RuntimeException(
61  'Mandatory TCA config setting "allowed" missing in field "' . $fieldName . '" of table "' . $result['tableName'] . '"',
62  1482250512
63  );
64  }
65 
66  // In case of vanilla uid, 0 is used to query relations by splitting $databaseRowFieldContent (possible defVals)
67  $MMuid = ‪MathUtility::canBeInterpretedAsInteger($result['databaseRow']['uid']) ? $result['databaseRow']['uid'] : 0;
68 
69  $relationHandler = GeneralUtility::makeInstance(RelationHandler::class);
70  $relationHandler->start(
71  $databaseRowFieldContent,
72  $fieldConfig['config']['allowed'] ?? '',
73  $fieldConfig['config']['MM'] ?? '',
74  $MMuid,
75  $result['tableName'] ?? '',
76  $fieldConfig['config'] ?? []
77  );
78  $relationHandler->getFromDB();
79  $relationHandler->processDeletePlaceholder();
80  $relations = $relationHandler->getResolvedItemArray();
81  foreach ($relations as $relation) {
82  $tableName = $relation['table'];
83  ‪$record = $relation['record'];
84  BackendUtility::workspaceOL($tableName, ‪$record);
85  $title = BackendUtility::getRecordTitle($tableName, ‪$record, false, false);
86  $items[] = [
87  'table' => $tableName,
88  'uid' => ‪$record['uid'] ?? null,
89  'title' => $title,
90  'row' => ‪$record,
91  ];
92  }
93 
94  // Register elements from clipboard
95  $allowed = ‪GeneralUtility::trimExplode(',', $fieldConfig['config']['allowed'], true);
96  $clipboard = GeneralUtility::makeInstance(Clipboard::class);
97  $clipboard->initializeClipboard();
98  if ($allowed[0] !== '*') {
99  // Only some tables, filter them:
100  foreach ($allowed as $tablename) {
101  foreach ($clipboard->elFromTable($tablename) as $recordUid) {
102  ‪$record = BackendUtility::getRecordWSOL($tablename, $recordUid);
103  $sanitizedClipboardElements[] = [
104  'title' => BackendUtility::getRecordTitle($tablename, ‪$record),
105  'value' => $tablename . '_' . $recordUid,
106  ];
107  }
108  }
109  } else {
110  // All tables allowed for relation:
111  $clipboardElements = array_keys($clipboard->elFromTable(''));
112  foreach ($clipboardElements as $elementValue) {
113  [$elementTable, $elementUid] = explode('|', $elementValue);
114  ‪$record = BackendUtility::getRecordWSOL($elementTable, (int)$elementUid);
115  $sanitizedClipboardElements[] = [
116  'title' => BackendUtility::getRecordTitle($elementTable, ‪$record),
117  'value' => $elementTable . '_' . $elementUid,
118  ];
119  }
120  }
121 
122  $result['databaseRow'][$fieldName] = $items;
123  $result['processedTca']['columns'][$fieldName]['config']['clipboardElements'] = $sanitizedClipboardElements;
124  }
125 
126  return $result;
127  }
128 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaGroup
Definition: TcaGroup.php:29
‪TYPO3\CMS\Backend\Clipboard\Clipboard
Definition: Clipboard.php:48
‪TYPO3\CMS\Core\Database\RelationHandler
Definition: RelationHandler.php:36
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger(mixed $var)
Definition: MathUtility.php:69
‪TYPO3\CMS\Webhooks\Message\$record
‪identifier readonly int readonly array $record
Definition: PageModificationMessage.php:36
‪TYPO3\CMS\Backend\Form\FormDataProvider
Definition: AbstractDatabaseRecordProvider.php:16
‪TYPO3\CMS\Backend\Form\FormDataProviderInterface
Definition: FormDataProviderInterface.php:23
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaGroup\addData
‪array addData(array $result)
Definition: TcaGroup.php:35
‪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