[TASK] Correct isTargetRenderType for FormDataProviders
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / FormDataProvider / TcaSelectItems.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
19 /**
20 * Resolve select items, set processed item list in processedTca, sanitize and resolve database field
21 */
22 class TcaSelectItems extends AbstractItemProvider implements FormDataProviderInterface
23 {
24 /**
25 * Resolve select items
26 *
27 * @param array $result
28 * @return array
29 * @throws \UnexpectedValueException
30 */
31 public function addData(array $result)
32 {
33 $table = $result['tableName'];
34
35 foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfig) {
36 if (empty($fieldConfig['config']['type']) || $fieldConfig['config']['type'] !== 'select') {
37 continue;
38 }
39
40 // Make sure we are only processing supported renderTypes
41 if (!$this->isTargetRenderType($fieldConfig)) {
42 continue;
43 }
44
45 $fieldConfig['config']['items'] = $this->sanitizeItemArray($fieldConfig['config']['items'], $table, $fieldName);
46 $fieldConfig['config']['maxitems'] = $this->sanitizeMaxItems($fieldConfig['config']['maxitems']);
47
48 $fieldConfig['config']['items'] = $this->addItemsFromPageTsConfig($result, $fieldName, $fieldConfig['config']['items']);
49 $fieldConfig['config']['items'] = $this->addItemsFromSpecial($result, $fieldName, $fieldConfig['config']['items']);
50 $fieldConfig['config']['items'] = $this->addItemsFromFolder($result, $fieldName, $fieldConfig['config']['items']);
51 $staticItems = $fieldConfig['config']['items'];
52
53 $fieldConfig['config']['items'] = $this->addItemsFromForeignTable($result, $fieldName, $fieldConfig['config']['items']);
54 $dynamicItems = array_diff_key($fieldConfig['config']['items'], $staticItems);
55
56 $fieldConfig['config']['items'] = $this->removeItemsByKeepItemsPageTsConfig($result, $fieldName, $fieldConfig['config']['items']);
57 $fieldConfig['config']['items'] = $this->removeItemsByRemoveItemsPageTsConfig($result, $fieldName, $fieldConfig['config']['items']);
58 $fieldConfig['config']['items'] = $this->removeItemsByUserLanguageFieldRestriction($result, $fieldName, $fieldConfig['config']['items']);
59 $fieldConfig['config']['items'] = $this->removeItemsByUserAuthMode($result, $fieldName, $fieldConfig['config']['items']);
60 $fieldConfig['config']['items'] = $this->removeItemsByDoktypeUserRestriction($result, $fieldName, $fieldConfig['config']['items']);
61
62 // Resolve "itemsProcFunc"
63 if (!empty($fieldConfig['config']['itemsProcFunc'])) {
64 $fieldConfig['config']['items'] = $this->resolveItemProcessorFunction($result, $fieldName, $fieldConfig['config']['items']);
65 // itemsProcFunc must not be used anymore
66 unset($fieldConfig['config']['itemsProcFunc']);
67 }
68
69 // Translate labels
70 $fieldConfig['config']['items'] = $this->translateLabels($result, $fieldConfig['config']['items'], $table, $fieldName);
71
72 $staticValues = $this->getStaticValues($fieldConfig['config']['items'], $dynamicItems);
73
74 // Keys may contain table names, so a numeric array is created
75 $fieldConfig['config']['items'] = array_values($fieldConfig['config']['items']);
76
77 $result['processedTca']['columns'][$fieldName] = $fieldConfig;
78 $result['databaseRow'][$fieldName] = $this->processSelectFieldValue($result, $fieldName, $staticValues);
79 }
80
81 return $result;
82 }
83
84 /**
85 * Determines whether the current field is a valid target for this DataProvider
86 *
87 * @param array $fieldConfig
88 * @return bool
89 */
90 protected function isTargetRenderType(array $fieldConfig)
91 {
92 return in_array(
93 $fieldConfig['config']['renderType'],
94 ['selectSingle', 'selectSingleBox', 'selectCheckBox', 'selectMultipleSideBySide'],
95 true
96 );
97 }
98 }