‪TYPO3CMS  9.5
Richtext.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
23 
31 {
43  public function ‪getConfiguration(string $table, string $field, int $pid, string $recordType, array $tcaFieldConf): array
44  {
45  // create instance of NodeFactory, ask for "text" element
46  //
47  // As soon an the Data handler starts using FormDataProviders, this class can vanish again, and the hack to
48  // test for specific rich text instances can be dropped: Split the "TcaText" data provider into multiple parts, each
49  // RTE should register and own data provider that does the transformation / configuration providing. This way,
50  // the explicit check for different RTE classes is removed from core and "hooked in" by the RTE's.
51 
52  // The main problem here is that all parameters that the processing needs is handed over to as TSconfig
53  // "dotted array" syntax. We convert at least the processing information available under "processing"
54  // together with pageTS, this way it can be overridden and understood in RteHtmlParser.
55  // However, all other parts of the core will depend on the non-dotted syntax (coming from YAML directly)
56 
57  $pageTs = $this->‪getPageTsConfiguration($table, $field, $pid, $recordType);
58 
59  // determine which preset to use
60  $usePreset = $pageTs['preset'] ?? $tcaFieldConf['richtextConfiguration'] ?? 'default';
61 
62  // load configuration from preset
63  $configuration = $this->‪loadConfigurationFromPreset($usePreset);
64 
65  // overlay preset configuration with pageTs
67  $configuration,
68  $this->‪addFlattenedPageTsConfig($pageTs)
69  );
70 
71  // Handle "mode" / "transformation" config when overridden
72  if (!isset($configuration['proc.']['mode']) && !isset($configuration['proc.']['overruleMode'])) {
73  $configuration['proc.']['overruleMode'] = 'default';
74  }
75 
76  return $configuration;
77  }
78 
86  protected function ‪loadConfigurationFromPreset(string $presetName = ''): array
87  {
88  $configuration = [];
89  if (!empty($presetName) && isset(‪$GLOBALS['TYPO3_CONF_VARS']['RTE']['Presets'][$presetName])) {
90  $fileLoader = GeneralUtility::makeInstance(YamlFileLoader::class);
91  $configuration = $fileLoader->load(‪$GLOBALS['TYPO3_CONF_VARS']['RTE']['Presets'][$presetName]);
92  // For future versions, you should however rely on the "processing" key and not the "proc" key.
93  if (is_array($configuration['processing'])) {
94  $configuration['proc.'] = $this->‪convertPlainArrayToTypoScriptArray($configuration['processing']);
95  }
96  }
97  return $configuration;
98  }
99 
106  protected function ‪getRtePageTsConfigOfPid(int $pid): array
107  {
108  return ‪BackendUtility::getPagesTSconfig($pid)['RTE.'] ?? [];
109  }
110 
119  protected function ‪convertPlainArrayToTypoScriptArray(array $plainArray)
120  {
121  $typoScriptArray = [];
122  foreach ($plainArray as $key => $value) {
123  if (is_array($value)) {
124  if (!isset($typoScriptArray[$key])) {
125  $typoScriptArray[$key] = 1;
126  }
127  $typoScriptArray[$key . '.'] = $this->‪convertPlainArrayToTypoScriptArray($value);
128  } else {
129  $typoScriptArray[$key] = $value === null ? '' : $value;
130  }
131  }
132  return $typoScriptArray;
133  }
134 
143  protected function ‪addFlattenedPageTsConfig(array $typoScriptArray): array
144  {
145  foreach ($typoScriptArray as $key => $data) {
146  if (substr($key, -1) !== '.') {
147  continue;
148  }
150  $typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
151  $typoScriptArray[substr($key, 0, -1)] = $typoScriptService->convertTypoScriptArrayToPlainArray($typoScriptArray[$key]);
152  }
153 
154  return $typoScriptArray;
155  }
156 
168  protected function ‪getPageTsConfiguration(string $table, string $field, int $pid, string $recordType): array
169  {
170  // Load PageTSconfig configuration
171  $fullPageTsConfig = $this->‪getRtePageTsConfigOfPid($pid);
172  $defaultPageTsConfigOverrides = $fullPageTsConfig['default.'] ?? null;
173  $fieldSpecificPageTsConfigOverrides = $fullPageTsConfig['config.'][$table . '.'][$field . '.'] ?? null;
174  unset($fullPageTsConfig['default.'], $fullPageTsConfig['config.']);
175 
176  // First use RTE.*
177  $rtePageTsConfiguration = $fullPageTsConfig;
178 
179  // Then overload with RTE.default.*
180  if (is_array($defaultPageTsConfigOverrides)) {
181  ‪ArrayUtility::mergeRecursiveWithOverrule($rtePageTsConfiguration, $defaultPageTsConfigOverrides);
182  }
183 
184  // Then overload with RTE.config.tt_content.bodytext
185  if (is_array($fieldSpecificPageTsConfigOverrides)) {
186  $fieldSpecificPageTsConfigOverridesWithoutType = $fieldSpecificPageTsConfigOverrides;
187  unset($fieldSpecificPageTsConfigOverridesWithoutType['types.']);
188  ‪ArrayUtility::mergeRecursiveWithOverrule($rtePageTsConfiguration, $fieldSpecificPageTsConfigOverridesWithoutType);
189 
190  // Then overload with RTE.config.tt_content.bodytext.types.textmedia
191  if (
192  $recordType
193  && isset($fieldSpecificPageTsConfigOverrides['types.'][$recordType . '.'])
194  && is_array($fieldSpecificPageTsConfigOverrides['types.'][$recordType . '.'])
195  ) {
197  $rtePageTsConfiguration,
198  $fieldSpecificPageTsConfigOverrides['types.'][$recordType . '.']
199  );
200  }
201  }
202 
203  return $rtePageTsConfiguration;
204  }
205 }
‪TYPO3\CMS\Core\Configuration\Richtext\addFlattenedPageTsConfig
‪array addFlattenedPageTsConfig(array $typoScriptArray)
Definition: Richtext.php:143
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:614
‪TYPO3\CMS\Core\Configuration\Richtext\getRtePageTsConfigOfPid
‪array getRtePageTsConfigOfPid(int $pid)
Definition: Richtext.php:106
‪TYPO3\CMS\Core\Configuration\Richtext\convertPlainArrayToTypoScriptArray
‪array convertPlainArrayToTypoScriptArray(array $plainArray)
Definition: Richtext.php:119
‪TYPO3\CMS\Core\Configuration\Richtext\getConfiguration
‪array getConfiguration(string $table, string $field, int $pid, string $recordType, array $tcaFieldConf)
Definition: Richtext.php:43
‪TYPO3\CMS\Core\Configuration\Richtext\getPageTsConfiguration
‪array getPageTsConfiguration(string $table, string $field, int $pid, string $recordType)
Definition: Richtext.php:168
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Core\TypoScript\TypoScriptService
Definition: TypoScriptService.php:23
‪TYPO3\CMS\Core\Configuration\Loader\YamlFileLoader
Definition: YamlFileLoader.php:41
‪TYPO3\CMS\Backend\Utility\BackendUtility\getPagesTSconfig
‪static array getPagesTSconfig($id, $rootLine=null, $returnPartArray=false)
Definition: BackendUtility.php:864
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:23
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Configuration
Definition: ConfigurationManager.php:2
‪TYPO3\CMS\Core\Configuration\Richtext\loadConfigurationFromPreset
‪array loadConfigurationFromPreset(string $presetName='')
Definition: Richtext.php:86
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Configuration\Richtext
Definition: Richtext.php:31