‪TYPO3CMS  10.4
FrontendConfigurationManager.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
27 
35 {
39  protected ‪$flexFormService;
40 
47  public function ‪__construct(
52  ) {
54 
55  $this->flexFormService = ‪$flexFormService;
56  }
57 
63  public function ‪getTypoScriptSetup(): array
64  {
65  return ‪$GLOBALS['TSFE']->tmpl->setup ?? [];
66  }
67 
76  protected function ‪getPluginConfiguration(string ‪$extensionName, string ‪$pluginName = null): array
77  {
78  $setup = $this->‪getTypoScriptSetup();
79  $pluginConfiguration = [];
80  if (isset($setup['plugin.']['tx_' . strtolower(‪$extensionName) . '.']) && is_array($setup['plugin.']['tx_' . strtolower(‪$extensionName) . '.'])) {
81  $pluginConfiguration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['plugin.']['tx_' . strtolower(‪$extensionName) . '.']);
82  }
83  if (‪$pluginName !== null) {
84  $pluginSignature = strtolower(‪$extensionName . '_' . ‪$pluginName);
85  if (isset($setup['plugin.']['tx_' . $pluginSignature . '.']) && is_array($setup['plugin.']['tx_' . $pluginSignature . '.'])) {
87  $pluginConfiguration,
88  $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['plugin.']['tx_' . $pluginSignature . '.'])
89  );
90  }
91  }
92  return $pluginConfiguration;
93  }
94 
106  protected function ‪getControllerConfiguration(string ‪$extensionName, string ‪$pluginName): array
107  {
108  $controllerConfiguration = ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][‪$extensionName]['plugins'][‪$pluginName]['controllers'] ?? [];
109  if (!is_array($controllerConfiguration)) {
110  $controllerConfiguration = [];
111  }
112  return $controllerConfiguration;
113  }
114 
123  protected function ‪getContextSpecificFrameworkConfiguration(array $frameworkConfiguration): array
124  {
125  $frameworkConfiguration = $this->‪overrideStoragePidIfStartingPointIsSet($frameworkConfiguration);
126  $frameworkConfiguration = $this->‪overrideConfigurationFromPlugin($frameworkConfiguration);
127  $frameworkConfiguration = $this->‪overrideConfigurationFromFlexForm($frameworkConfiguration);
128  return $frameworkConfiguration;
129  }
130 
138  protected function ‪overrideStoragePidIfStartingPointIsSet(array $frameworkConfiguration): array
139  {
140  $pages = $this->contentObject->data['pages'];
141  if (is_string($pages) && $pages !== '') {
142  $list = [];
143  if ($this->contentObject->data['recursive'] > 0) {
144  $explodedPages = ‪GeneralUtility::trimExplode(',', $pages);
145  foreach ($explodedPages as $pid) {
146  $pids = $this->contentObject->getTreeList($pid, $this->contentObject->data['recursive']);
147  if ($pids !== '') {
148  $list[] = $pids;
149  }
150  }
151  }
152  if (!empty($list)) {
153  $pages = $pages . ',' . implode(',', $list);
154  }
155  ‪ArrayUtility::mergeRecursiveWithOverrule($frameworkConfiguration, [
156  'persistence' => [
157  'storagePid' => $pages
158  ]
159  ]);
160  }
161  return $frameworkConfiguration;
162  }
163 
170  protected function ‪overrideConfigurationFromPlugin(array $frameworkConfiguration): array
171  {
172  $setup = $this->‪getTypoScriptSetup();
173  $pluginSignature = strtolower($frameworkConfiguration['extensionName'] . '_' . $frameworkConfiguration['pluginName']);
174  $pluginConfiguration = $setup['plugin.']['tx_' . $pluginSignature . '.'];
175  if (is_array($pluginConfiguration)) {
176  $pluginConfiguration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($pluginConfiguration);
177  $frameworkConfiguration = $this->‪mergeConfigurationIntoFrameworkConfiguration($frameworkConfiguration, $pluginConfiguration, 'settings');
178  $frameworkConfiguration = $this->‪mergeConfigurationIntoFrameworkConfiguration($frameworkConfiguration, $pluginConfiguration, 'persistence');
179  $frameworkConfiguration = $this->‪mergeConfigurationIntoFrameworkConfiguration($frameworkConfiguration, $pluginConfiguration, 'view');
180  }
181  return $frameworkConfiguration;
182  }
183 
192  protected function ‪overrideConfigurationFromFlexForm(array $frameworkConfiguration): array
193  {
194  $flexFormConfiguration = $this->contentObject->data['pi_flexform'];
195  if (is_string($flexFormConfiguration)) {
196  if ($flexFormConfiguration !== '') {
197  $flexFormConfiguration = $this->flexFormService->convertFlexFormContentToArray($flexFormConfiguration);
198  } else {
199  $flexFormConfiguration = [];
200  }
201  }
202  if (is_array($flexFormConfiguration) && !empty($flexFormConfiguration)) {
203  $frameworkConfiguration = $this->‪mergeConfigurationIntoFrameworkConfiguration($frameworkConfiguration, $flexFormConfiguration, 'settings');
204  $frameworkConfiguration = $this->‪mergeConfigurationIntoFrameworkConfiguration($frameworkConfiguration, $flexFormConfiguration, 'persistence');
205  $frameworkConfiguration = $this->‪mergeConfigurationIntoFrameworkConfiguration($frameworkConfiguration, $flexFormConfiguration, 'view');
206  $frameworkConfiguration = $this->‪overrideControllerConfigurationWithSwitchableControllerActionsFromFlexForm($frameworkConfiguration, $flexFormConfiguration);
207  }
208  return $frameworkConfiguration;
209  }
210 
219  protected function ‪mergeConfigurationIntoFrameworkConfiguration(array $frameworkConfiguration, array ‪$configuration, string $configurationPartName): array
220  {
221  if (isset(‪$configuration[$configurationPartName]) && is_array(‪$configuration[$configurationPartName])) {
222  if (isset($frameworkConfiguration[$configurationPartName]) && is_array($frameworkConfiguration[$configurationPartName])) {
223  ‪ArrayUtility::mergeRecursiveWithOverrule($frameworkConfiguration[$configurationPartName], ‪$configuration[$configurationPartName]);
224  } else {
225  $frameworkConfiguration[$configurationPartName] = ‪$configuration[$configurationPartName];
226  }
227  }
228  return $frameworkConfiguration;
229  }
230 
241  protected function ‪overrideControllerConfigurationWithSwitchableControllerActionsFromFlexForm(array $frameworkConfiguration, array $flexFormConfiguration): array
242  {
243  if (!isset($flexFormConfiguration['switchableControllerActions']) || is_array($flexFormConfiguration['switchableControllerActions'])) {
244  return $frameworkConfiguration;
245  }
246  // As "," is the flexForm field value delimiter, we need to use ";" as in-field delimiter. That's why we need to replace ; by , first.
247  // The expected format is: "Controller1->action2;Controller2->action3;Controller2->action1"
248  $switchableControllerActionPartsFromFlexForm = ‪GeneralUtility::trimExplode(',', str_replace(';', ',', $flexFormConfiguration['switchableControllerActions']), true);
249  $overriddenControllerConfiguration = [];
250  foreach ($switchableControllerActionPartsFromFlexForm as $switchableControllerActionPartFromFlexForm) {
251  [$controller, $action] = ‪GeneralUtility::trimExplode('->', $switchableControllerActionPartFromFlexForm);
252  if (empty($controller) || empty($action)) {
253  throw new ‪ParseErrorException('Controller or action were empty when overriding switchableControllerActions from flexForm.', 1257146403);
254  }
255  $overriddenControllerConfiguration[$controller][] = $action;
256  }
257  if (!empty($overriddenControllerConfiguration)) {
258  $this->‪overrideControllerConfigurationWithSwitchableControllerActions($frameworkConfiguration, $overriddenControllerConfiguration);
259  }
260  return $frameworkConfiguration;
261  }
262 
270  protected function ‪getRecursiveStoragePids(array $storagePids, int $recursionDepth = 0): array
271  {
272  array_map('intval', $storagePids);
273 
274  if ($recursionDepth <= 0) {
275  return $storagePids;
276  }
277 
278  $recursiveStoragePids = [];
279  foreach ($storagePids as $startPid) {
280  $pids = $this->‪getContentObject()->‪getTreeList($startPid, $recursionDepth, 0);
281  foreach (‪GeneralUtility::intExplode(',', $pids, true) as $pid) {
282  $recursiveStoragePids[] = $pid;
283  }
284  }
285  return array_unique($recursiveStoragePids);
286  }
287 }
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$pluginName
‪string $pluginName
Definition: AbstractConfigurationManager.php:68
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\getContentObject
‪TYPO3 CMS Frontend ContentObject ContentObjectRenderer null getContentObject()
Definition: AbstractConfigurationManager.php:106
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\$flexFormService
‪TYPO3 CMS Core Service FlexFormService $flexFormService
Definition: FrontendConfigurationManager.php:38
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:654
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager
Definition: AbstractConfigurationManager.php:34
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$environmentService
‪TYPO3 CMS Extbase Service EnvironmentService $environmentService
Definition: AbstractConfigurationManager.php:78
‪TYPO3\CMS\Extbase\Object\ObjectManagerInterface
Definition: ObjectManagerInterface.php:26
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$typoScriptService
‪TYPO3 CMS Core TypoScript TypoScriptService $typoScriptService
Definition: AbstractConfigurationManager.php:56
‪TYPO3\CMS\Core\Service\FlexFormService
Definition: FlexFormService.php:25
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager
Definition: FrontendConfigurationManager.php:35
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\getControllerConfiguration
‪array getControllerConfiguration(string $extensionName, string $pluginName)
Definition: FrontendConfigurationManager.php:105
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$configuration
‪array $configuration
Definition: AbstractConfigurationManager.php:44
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\getContextSpecificFrameworkConfiguration
‪array getContextSpecificFrameworkConfiguration(array $frameworkConfiguration)
Definition: FrontendConfigurationManager.php:122
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\overrideControllerConfigurationWithSwitchableControllerActionsFromFlexForm
‪array overrideControllerConfigurationWithSwitchableControllerActionsFromFlexForm(array $frameworkConfiguration, array $flexFormConfiguration)
Definition: FrontendConfigurationManager.php:240
‪TYPO3\CMS\Extbase\Configuration\Exception\ParseErrorException
Definition: ParseErrorException.php:26
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\overrideConfigurationFromPlugin
‪array overrideConfigurationFromPlugin(array $frameworkConfiguration)
Definition: FrontendConfigurationManager.php:169
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\getPluginConfiguration
‪array getPluginConfiguration(string $extensionName, string $pluginName=null)
Definition: FrontendConfigurationManager.php:75
‪TYPO3\CMS\Extbase\Service\EnvironmentService
Definition: EnvironmentService.php:27
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\mergeConfigurationIntoFrameworkConfiguration
‪array mergeConfigurationIntoFrameworkConfiguration(array $frameworkConfiguration, array $configuration, string $configurationPartName)
Definition: FrontendConfigurationManager.php:218
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪TYPO3\CMS\Core\TypoScript\TypoScriptService
Definition: TypoScriptService.php:25
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\overrideConfigurationFromFlexForm
‪array overrideConfigurationFromFlexForm(array $frameworkConfiguration)
Definition: FrontendConfigurationManager.php:191
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\getRecursiveStoragePids
‪array int[] getRecursiveStoragePids(array $storagePids, int $recursionDepth=0)
Definition: FrontendConfigurationManager.php:269
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\overrideStoragePidIfStartingPointIsSet
‪array overrideStoragePidIfStartingPointIsSet(array $frameworkConfiguration)
Definition: FrontendConfigurationManager.php:137
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility\intExplode
‪static int[] intExplode($delimiter, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:988
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\overrideControllerConfigurationWithSwitchableControllerActions
‪overrideControllerConfigurationWithSwitchableControllerActions(array &$frameworkConfiguration, array $switchableControllerActions)
Definition: AbstractConfigurationManager.php:248
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\__construct
‪__construct(ObjectManagerInterface $objectManager, TypoScriptService $typoScriptService, EnvironmentService $environmentService, FlexFormService $flexFormService)
Definition: FrontendConfigurationManager.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Extbase\Configuration
Definition: AbstractConfigurationManager.php:18
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\getTypoScriptSetup
‪array getTypoScriptSetup()
Definition: FrontendConfigurationManager.php:62
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\getTreeList
‪string getTreeList($id, $depth, $begin=0, $dontCheckEnableFields=false, $addSelectFields='', $moreWhereClauses='', array $prevId_array=[], $recursionLevel=0)
Definition: ContentObjectRenderer.php:5945
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$extensionName
‪string $extensionName
Definition: AbstractConfigurationManager.php:62
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$objectManager
‪TYPO3 CMS Extbase Object ObjectManagerInterface $objectManager
Definition: AbstractConfigurationManager.php:52