[TASK] Replace icon by IconFactory: actions-edit-restore-edit
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / FormDataProvider / DatabaseRowGroupRelations.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 DatabaseRowGroupRelations 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 be renamed to TcaGroup to be in line with the other element based classes
33 * @todo: Should not implode valid values with | again, container & elements should work
34 * @todo: with the array as it was done for select items
35 * @throws \UnexpectedValueException
36 */
37 public function addData(array $result) {
38 foreach ($result['vanillaTableTca']['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') {
63 /** @var $relationHandler RelationHandler */
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
88 }