‪TYPO3CMS  10.4
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 
27 
32 {
41  public function ‪addData(array $result)
42  {
43  foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfig) {
44  if (empty($fieldConfig['config']['type'])
45  || $fieldConfig['config']['type'] !== 'group'
46  || empty($fieldConfig['config']['internal_type'])
47  ) {
48  continue;
49  }
50 
51  // Sanitize max items, set to 99999 if not defined
52  $result['processedTca']['columns'][$fieldName]['config']['maxitems'] = ‪MathUtility::forceIntegerInRange(
53  $fieldConfig['config']['maxitems'] ?? 0,
54  0,
55  99999
56  );
57  if ($result['processedTca']['columns'][$fieldName]['config']['maxitems'] === 0) {
58  $result['processedTca']['columns'][$fieldName]['config']['maxitems'] = 99999;
59  }
60 
61  $databaseRowFieldContent = '';
62  if (!empty($result['databaseRow'][$fieldName])) {
63  $databaseRowFieldContent = (string)$result['databaseRow'][$fieldName];
64  }
65 
66  $items = [];
67  $sanitizedClipboardElements = [];
68  $internalType = $fieldConfig['config']['internal_type'];
69  if ($internalType === 'db') {
70  if (empty($fieldConfig['config']['allowed'])) {
71  throw new \RuntimeException(
72  'Mandatory TCA config setting "allowed" missing in field "' . $fieldName . '" of table "' . $result['tableName'] . '"',
73  1482250512
74  );
75  }
76 
77  // In case of vanilla uid, 0 is used to query relations by splitting $databaseRowFieldContent (possible defVals)
78  $MMuid = ‪MathUtility::canBeInterpretedAsInteger($result['databaseRow']['uid']) ? $result['databaseRow']['uid'] : 0;
79 
80  $relationHandler = GeneralUtility::makeInstance(RelationHandler::class);
81  $relationHandler->start(
82  $databaseRowFieldContent,
83  $fieldConfig['config']['allowed'],
84  $fieldConfig['config']['MM'],
85  $MMuid,
86  $result['tableName'],
87  $fieldConfig['config']
88  );
89  $relationHandler->getFromDB();
90  $relationHandler->processDeletePlaceholder();
91  $relations = $relationHandler->getResolvedItemArray();
92  foreach ($relations as $relation) {
93  $tableName = $relation['table'];
94  $uid = $relation['uid'];
95  $record = ‪BackendUtility::getRecordWSOL($tableName, $uid);
96  $title = ‪BackendUtility::getRecordTitle($tableName, $record, false, false);
97  $items[] = [
98  'table' => $tableName,
99  'uid' => $record['uid'] ?? null,
100  'title' => $title,
101  'row' => $record,
102  ];
103  }
104 
105  // Register elements from clipboard
106  $allowed = ‪GeneralUtility::trimExplode(',', $fieldConfig['config']['allowed'], true);
107  $clipboard = GeneralUtility::makeInstance(Clipboard::class);
108  $clipboard->initializeClipboard();
109  if ($allowed[0] !== '*') {
110  // Only some tables, filter them:
111  foreach ($allowed as $tablename) {
112  foreach ($clipboard->elFromTable($tablename) as $recordUid) {
113  $record = ‪BackendUtility::getRecordWSOL($tablename, $recordUid);
114  $sanitizedClipboardElements[] = [
115  'title' => ‪BackendUtility::getRecordTitle($tablename, $record),
116  'value' => $tablename . '_' . $recordUid,
117  ];
118  }
119  }
120  } else {
121  // All tables allowed for relation:
122  $clipboardElements = array_keys($clipboard->elFromTable(''));
123  foreach ($clipboardElements as $elementValue) {
124  [$elementTable, $elementUid] = explode('|', $elementValue);
125  $record = ‪BackendUtility::getRecordWSOL($elementTable, (int)$elementUid);
126  $sanitizedClipboardElements[] = [
127  'title' => ‪BackendUtility::getRecordTitle($elementTable, $record),
128  'value' => $elementTable . '_' . $elementUid,
129  ];
130  }
131  }
132  } elseif ($internalType === 'folder') {
133  // Simple list of folders
134  $folderList = ‪GeneralUtility::trimExplode(',', $databaseRowFieldContent, true);
135  foreach ($folderList as $folder) {
136  if (empty($folder)) {
137  continue;
138  }
139  try {
140  $folderObject = GeneralUtility::makeInstance(ResourceFactory::class)->retrieveFileOrFolderObject($folder);
141  if ($folderObject instanceof ‪Folder) {
142  $items[] = [
143  'folder' => $folder,
144  ];
145  }
146  } catch (‪Exception $exception) {
147  continue;
148  }
149  }
150  } else {
151  throw new \UnexpectedValueException(
152  'TCA internal_type of field "' . $fieldName . '" in table ' . $result['tableName']
153  . ' must be set to "db" or "folder".',
154  1438780511
155  );
156  }
157 
158  $result['databaseRow'][$fieldName] = $items;
159  $result['processedTca']['columns'][$fieldName]['config']['clipboardElements'] = $sanitizedClipboardElements;
160  }
161 
162  return $result;
163  }
164 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaGroup
Definition: TcaGroup.php:32
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger($var)
Definition: MathUtility.php:74
‪TYPO3\CMS\Backend\Clipboard\Clipboard
Definition: Clipboard.php:43
‪TYPO3\CMS\Core\Database\RelationHandler
Definition: RelationHandler.php:35
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:32
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:37
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:41
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordTitle
‪static string getRecordTitle($table, $row, $prep=false, $forceResult=true)
Definition: BackendUtility.php:1541
‪TYPO3\CMS\Backend\Form\FormDataProvider
Definition: AbstractDatabaseRecordProvider.php:16
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordWSOL
‪static array getRecordWSOL( $table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)
Definition: BackendUtility.php:139
‪TYPO3\CMS\Backend\Form\FormDataProviderInterface
Definition: FormDataProviderInterface.php:23
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪TYPO3\CMS\Core\Resource\Exception
Definition: Exception.php:22
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaGroup\addData
‪array addData(array $result)
Definition: TcaGroup.php:41
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Resource\Exception
Definition: AbstractFileOperationException.php:16