[TASK] Rename DatabaseRowGroupRelations to TcaGroups
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / FormDataProvider / TcaGroup.php
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
17 use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
18 use TYPO3\CMS\Core\Database\RelationHandler;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Core\Utility\PathUtility;
21
22 /**
23 * Resolve databaseRow field content to the real connected rows for type=group
24 */
25 class TcaGroup implements FormDataProviderInterface {
26
27 /**
28 * Initialize new row with default values from various sources
29 *
30 * @param array $result
31 * @return array
32 * @todo: Should not implode valid values with | again, container & elements should work
33 * @todo: with the array as it was done for select items
34 * @throws \UnexpectedValueException
35 */
36 public function addData(array $result) {
37 foreach ($result['vanillaTableTca']['columns'] as $fieldName => $fieldConfig) {
38 if (empty($fieldConfig['config']['type'])
39 || $fieldConfig['config']['type'] !== 'group'
40 || empty($fieldConfig['config']['internal_type'])
41 ) {
42 continue;
43 }
44
45 $databaseRowFieldContent = '';
46 if (!empty($result['databaseRow'][$fieldName])) {
47 $databaseRowFieldContent = (string)$result['databaseRow'][$fieldName];
48 }
49
50 $internalType = $fieldConfig['config']['internal_type'];
51 if ($internalType === 'file_reference' || $internalType === 'file') {
52 $files = array();
53 // Simple list of files
54 $fileList = GeneralUtility::trimExplode(',', $databaseRowFieldContent, TRUE);
55 foreach ($fileList as $file) {
56 if ($file) {
57 $files[] = rawurlencode($file) . '|' . rawurlencode(PathUtility::basename($file));
58 }
59 }
60 $result['databaseRow'][$fieldName] = implode(',', $files);
61 } elseif ($internalType === 'db') {
62 /** @var $relationHandler RelationHandler */
63 $relationHandler = GeneralUtility::makeInstance(RelationHandler::class);
64 $relationHandler->start(
65 $databaseRowFieldContent,
66 $fieldConfig['config']['allowed'],
67 $fieldConfig['config']['MM'],
68 $result['databaseRow']['uid'],
69 $result['tableName'],
70 $fieldConfig['config']
71 );
72 $relationHandler->getFromDB();
73 $result['databaseRow'][$fieldName] = $relationHandler->readyForInterface();
74 } else {
75 // @todo: "folder" is a valid internal_type, too.
76 throw new \UnexpectedValueException(
77 'TCA internal_type of field "' . $fieldName . '" in table ' . $result['tableName']
78 .' must be set to either "db", "file" or "file_reference"',
79 1438780511
80 );
81 }
82 }
83
84 return $result;
85 }
86
87 }