TYPO3 CMS  TYPO3_7-6
TcaGroup.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
24 
29 {
39  public function addData(array $result)
40  {
41  foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfig) {
42  if (empty($fieldConfig['config']['type'])
43  || $fieldConfig['config']['type'] !== 'group'
44  || empty($fieldConfig['config']['internal_type'])
45  ) {
46  continue;
47  }
48 
49  $databaseRowFieldContent = '';
50  if (!empty($result['databaseRow'][$fieldName])) {
51  $databaseRowFieldContent = (string)$result['databaseRow'][$fieldName];
52  }
53 
54  $internalType = $fieldConfig['config']['internal_type'];
55  if ($internalType === 'file_reference' || $internalType === 'file') {
56  $files = [];
57  // Simple list of files
58  $fileList = GeneralUtility::trimExplode(',', $databaseRowFieldContent, true);
59  foreach ($fileList as $file) {
60  if ($file) {
61  $files[] = rawurlencode($file) . '|' . rawurlencode(PathUtility::basename($file));
62  }
63  }
64  $result['databaseRow'][$fieldName] = implode(',', $files);
65  } elseif ($internalType === 'db') {
67  $relationHandler = GeneralUtility::makeInstance(RelationHandler::class);
68  $relationHandler->start(
69  $databaseRowFieldContent,
70  $fieldConfig['config']['allowed'],
71  $fieldConfig['config']['MM'],
72  $result['databaseRow']['uid'],
73  $result['tableName'],
74  $fieldConfig['config']
75  );
76  $relationHandler->getFromDB();
77  $result['databaseRow'][$fieldName] = $relationHandler->readyForInterface();
78  } elseif ($internalType === 'folder') {
79  $folders = [];
80  // Simple list of folders
81  $folderList = GeneralUtility::trimExplode(',', $databaseRowFieldContent, true);
82  foreach ($folderList as $folder) {
83  if (empty($folder)) {
84  continue;
85  }
86  try {
87  $folderObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject($folder);
88  if ($folderObject instanceof Folder) {
89  $folderName = PathUtility::basename($folderObject->getIdentifier());
90  $folders[] = rawurlencode($folder) . '|' . rawurlencode($folderName);
91  }
92  } catch (Exception $exception) {
93  continue;
94  }
95  }
96  $result['databaseRow'][$fieldName] = implode(',', $folders);
97  } else {
98  throw new \UnexpectedValueException(
99  'TCA internal_type of field "' . $fieldName . '" in table ' . $result['tableName']
100  . ' must be set to either "db", "file" or "file_reference"',
101  1438780511
102  );
103  }
104  }
105 
106  return $result;
107  }
108 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)