TYPO3  7.6
TcaGroup.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Form\FormDataProvider;
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 
21 
26 {
36  public function addData(array $result)
37  {
38  foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfig) {
39  if (empty($fieldConfig['config']['type'])
40  || $fieldConfig['config']['type'] !== 'group'
41  || empty($fieldConfig['config']['internal_type'])
42  ) {
43  continue;
44  }
45 
46  $databaseRowFieldContent = '';
47  if (!empty($result['databaseRow'][$fieldName])) {
48  $databaseRowFieldContent = (string)$result['databaseRow'][$fieldName];
49  }
50 
51  $internalType = $fieldConfig['config']['internal_type'];
52  if ($internalType === 'file_reference' || $internalType === 'file') {
53  $files = array();
54  // Simple list of files
55  $fileList = GeneralUtility::trimExplode(',', $databaseRowFieldContent, true);
56  foreach ($fileList as $file) {
57  if ($file) {
58  $files[] = rawurlencode($file) . '|' . rawurlencode(PathUtility::basename($file));
59  }
60  }
61  $result['databaseRow'][$fieldName] = implode(',', $files);
62  } elseif ($internalType === 'db') {
64  $relationHandler = GeneralUtility::makeInstance(RelationHandler::class);
65  $relationHandler->start(
66  $databaseRowFieldContent,
67  $fieldConfig['config']['allowed'],
68  $fieldConfig['config']['MM'],
69  $result['databaseRow']['uid'],
70  $result['tableName'],
71  $fieldConfig['config']
72  );
73  $relationHandler->getFromDB();
74  $result['databaseRow'][$fieldName] = $relationHandler->readyForInterface();
75  } else {
76  // @todo: "folder" is a valid internal_type, too.
77  throw new \UnexpectedValueException(
78  'TCA internal_type of field "' . $fieldName . '" in table ' . $result['tableName']
79  . ' must be set to either "db", "file" or "file_reference"',
80  1438780511
81  );
82  }
83  }
84 
85  return $result;
86  }
87 }