[TASK] Move LanguageService to EXT:core
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / FormDataProvider / PageTsConfigMerged.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\Utility\ArrayUtility;
19
20 /**
21 * Page TsConfig relevant for this record
22 */
23 class PageTsConfigMerged implements FormDataProviderInterface
24 {
25 /**
26 * Merge type specific page TS to pageTsConfig
27 *
28 * @param array $result
29 * @return array
30 */
31 public function addData(array $result)
32 {
33 $mergedTsConfig = $result['pageTsConfig'];
34
35 if (empty($result['pageTsConfig']['TCEFORM.']) || !is_array($result['pageTsConfig']['TCEFORM.'])) {
36 $result['pageTsConfig'] = $mergedTsConfig;
37 return $result;
38 }
39
40 $mergedTsConfig = $result['pageTsConfig'];
41 $type = $result['recordTypeValue'];
42 $table = $result['tableName'];
43
44 // Merge TCEFORM.[table name].[field].types.[type] over TCEFORM.[table name].[field]
45 if (!empty($result['pageTsConfig']['TCEFORM.'][$table . '.'])
46 && is_array($result['pageTsConfig']['TCEFORM.'][$table . '.'])
47 ) {
48 foreach ($result['pageTsConfig']['TCEFORM.'][$table . '.'] as $fieldNameWithDot => $fullFieldConfiguration) {
49 $newFieldConfiguration = $fullFieldConfiguration;
50 if (!empty($fullFieldConfiguration['types.']) && is_array($fullFieldConfiguration['types.'])) {
51 $typeSpecificConfiguration = $newFieldConfiguration['types.'];
52 unset($newFieldConfiguration['types.']);
53 if (!empty($typeSpecificConfiguration[$type . '.']) && is_array($typeSpecificConfiguration[$type . '.'])) {
54 ArrayUtility::mergeRecursiveWithOverrule($newFieldConfiguration, $typeSpecificConfiguration[$type . '.']);
55 }
56 }
57 $mergedTsConfig['TCEFORM.'][$table . '.'][$fieldNameWithDot] = $newFieldConfiguration;
58 }
59 }
60
61 $result['pageTsConfig'] = $mergedTsConfig;
62
63 return $result;
64 }
65 }