‪TYPO3CMS  9.5
FrontendConfigurationManager.php
Go to the documentation of this file.
1 <?php
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 
19 
27 {
31  protected ‪$flexFormService;
32 
36  public function ‪injectFlexFormService(\‪TYPO3\CMS\Core\Service\FlexFormService ‪$flexFormService)
37  {
38  $this->flexFormService = ‪$flexFormService;
39  }
40 
46  public function ‪getTypoScriptSetup()
47  {
48  return ‪$GLOBALS['TSFE']->tmpl->setup;
49  }
50 
60  {
61  $setup = $this->‪getTypoScriptSetup();
62  $pluginConfiguration = [];
63  if (isset($setup['plugin.']['tx_' . strtolower(‪$extensionName) . '.']) && is_array($setup['plugin.']['tx_' . strtolower(‪$extensionName) . '.'])) {
64  $pluginConfiguration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['plugin.']['tx_' . strtolower(‪$extensionName) . '.']);
65  }
66  if (‪$pluginName !== null) {
67  $pluginSignature = strtolower(‪$extensionName . '_' . ‪$pluginName);
68  if (isset($setup['plugin.']['tx_' . $pluginSignature . '.']) && is_array($setup['plugin.']['tx_' . $pluginSignature . '.'])) {
70  $pluginConfiguration,
71  $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['plugin.']['tx_' . $pluginSignature . '.'])
72  );
73  }
74  }
75  return $pluginConfiguration;
76  }
77 
90  {
91  $switchableControllerActions = ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][‪$extensionName]['plugins'][‪$pluginName]['controllers'] ?? [];
92  if (!is_array($switchableControllerActions)) {
93  $switchableControllerActions = [];
94  }
95  return $switchableControllerActions;
96  }
97 
106  protected function ‪getContextSpecificFrameworkConfiguration(array $frameworkConfiguration)
107  {
108  $frameworkConfiguration = $this->‪overrideStoragePidIfStartingPointIsSet($frameworkConfiguration);
109  $frameworkConfiguration = $this->‪overrideConfigurationFromPlugin($frameworkConfiguration);
110  $frameworkConfiguration = $this->‪overrideConfigurationFromFlexForm($frameworkConfiguration);
111  return $frameworkConfiguration;
112  }
113 
121  protected function ‪overrideStoragePidIfStartingPointIsSet(array $frameworkConfiguration)
122  {
123  $pages = $this->contentObject->data['pages'];
124  if (is_string($pages) && $pages !== '') {
125  $list = [];
126  if ($this->contentObject->data['recursive'] > 0) {
127  $explodedPages = GeneralUtility::trimExplode(',', $pages);
128  foreach ($explodedPages as $pid) {
129  $pids = $this->contentObject->getTreeList($pid, $this->contentObject->data['recursive']);
130  if ($pids !== '') {
131  $list[] = $pids;
132  }
133  }
134  }
135  if (!empty($list)) {
136  $pages = $pages . ',' . implode(',', $list);
137  }
138  ‪ArrayUtility::mergeRecursiveWithOverrule($frameworkConfiguration, [
139  'persistence' => [
140  'storagePid' => $pages
141  ]
142  ]);
143  }
144  return $frameworkConfiguration;
145  }
146 
153  protected function ‪overrideConfigurationFromPlugin(array $frameworkConfiguration)
154  {
155  $setup = $this->‪getTypoScriptSetup();
156  $pluginSignature = strtolower($frameworkConfiguration['extensionName'] . '_' . $frameworkConfiguration['pluginName']);
157  $pluginConfiguration = $setup['plugin.']['tx_' . $pluginSignature . '.'];
158  if (is_array($pluginConfiguration)) {
159  $pluginConfiguration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($pluginConfiguration);
160  $frameworkConfiguration = $this->‪mergeConfigurationIntoFrameworkConfiguration($frameworkConfiguration, $pluginConfiguration, 'settings');
161  $frameworkConfiguration = $this->‪mergeConfigurationIntoFrameworkConfiguration($frameworkConfiguration, $pluginConfiguration, 'persistence');
162  $frameworkConfiguration = $this->‪mergeConfigurationIntoFrameworkConfiguration($frameworkConfiguration, $pluginConfiguration, 'view');
163  }
164  return $frameworkConfiguration;
165  }
166 
174  protected function ‪overrideConfigurationFromFlexForm(array $frameworkConfiguration)
175  {
176  $flexFormConfiguration = $this->contentObject->data['pi_flexform'];
177  if (is_string($flexFormConfiguration)) {
178  if ($flexFormConfiguration !== '') {
179  $flexFormConfiguration = $this->flexFormService->convertFlexFormContentToArray($flexFormConfiguration);
180  } else {
181  $flexFormConfiguration = [];
182  }
183  }
184  if (is_array($flexFormConfiguration) && !empty($flexFormConfiguration)) {
185  $frameworkConfiguration = $this->‪mergeConfigurationIntoFrameworkConfiguration($frameworkConfiguration, $flexFormConfiguration, 'settings');
186  $frameworkConfiguration = $this->‪mergeConfigurationIntoFrameworkConfiguration($frameworkConfiguration, $flexFormConfiguration, 'persistence');
187  $frameworkConfiguration = $this->‪mergeConfigurationIntoFrameworkConfiguration($frameworkConfiguration, $flexFormConfiguration, 'view');
188  $frameworkConfiguration = $this->‪overrideSwitchableControllerActionsFromFlexForm($frameworkConfiguration, $flexFormConfiguration);
189  }
190  return $frameworkConfiguration;
191  }
192 
201  protected function ‪mergeConfigurationIntoFrameworkConfiguration(array $frameworkConfiguration, array ‪$configuration, $configurationPartName)
202  {
203  if (isset(‪$configuration[$configurationPartName]) && is_array(‪$configuration[$configurationPartName])) {
204  if (isset($frameworkConfiguration[$configurationPartName]) && is_array($frameworkConfiguration[$configurationPartName])) {
205  ‪ArrayUtility::mergeRecursiveWithOverrule($frameworkConfiguration[$configurationPartName], ‪$configuration[$configurationPartName]);
206  } else {
207  $frameworkConfiguration[$configurationPartName] = ‪$configuration[$configurationPartName];
208  }
209  }
210  return $frameworkConfiguration;
211  }
212 
221  protected function ‪overrideSwitchableControllerActionsFromFlexForm(array $frameworkConfiguration, array $flexFormConfiguration)
222  {
223  if (!isset($flexFormConfiguration['switchableControllerActions']) || is_array($flexFormConfiguration['switchableControllerActions'])) {
224  return $frameworkConfiguration;
225  }
226  // As "," is the flexForm field value delimiter, we need to use ";" as in-field delimiter. That's why we need to replace ; by , first.
227  // The expected format is: "Controller1->action2;Controller2->action3;Controller2->action1"
228  $switchableControllerActionPartsFromFlexForm = GeneralUtility::trimExplode(',', str_replace(';', ',', $flexFormConfiguration['switchableControllerActions']), true);
229  $newSwitchableControllerActionsFromFlexForm = [];
230  foreach ($switchableControllerActionPartsFromFlexForm as $switchableControllerActionPartFromFlexForm) {
231  list($controller, $action) = GeneralUtility::trimExplode('->', $switchableControllerActionPartFromFlexForm);
232  if (empty($controller) || empty($action)) {
233  throw new \TYPO3\CMS\Extbase\Configuration\Exception\ParseErrorException('Controller or action were empty when overriding switchableControllerActions from flexForm.', 1257146403);
234  }
235  $newSwitchableControllerActionsFromFlexForm[$controller][] = $action;
236  }
237  if (!empty($newSwitchableControllerActionsFromFlexForm)) {
238  $this->‪overrideSwitchableControllerActions($frameworkConfiguration, $newSwitchableControllerActionsFromFlexForm);
239  }
240  return $frameworkConfiguration;
241  }
242 
250  protected function ‪getRecursiveStoragePids($storagePid, $recursionDepth = 0)
251  {
252  if ($recursionDepth <= 0) {
253  return $storagePid;
254  }
255 
256  $recursiveStoragePids = '';
257  $storagePids = GeneralUtility::intExplode(',', $storagePid);
258  foreach ($storagePids as $startPid) {
259  $pids = $this->‪getContentObject()->getTreeList($startPid, $recursionDepth, 0);
260  if ((string)$pids !== '') {
261  $recursiveStoragePids .= $pids . ',';
262  }
263  }
264  return rtrim($recursiveStoragePids, ',');
265  }
266 }
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\getRecursiveStoragePids
‪string getRecursiveStoragePids($storagePid, $recursionDepth=0)
Definition: FrontendConfigurationManager.php:249
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$pluginName
‪string $pluginName
Definition: AbstractConfigurationManager.php:56
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\getContentObject
‪TYPO3 CMS Frontend ContentObject ContentObjectRenderer null getContentObject()
Definition: AbstractConfigurationManager.php:103
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\$flexFormService
‪TYPO3 CMS Core Service FlexFormService $flexFormService
Definition: FrontendConfigurationManager.php:30
‪TYPO3
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\getSwitchableControllerActions
‪array getSwitchableControllerActions($extensionName, $pluginName)
Definition: FrontendConfigurationManager.php:88
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\injectFlexFormService
‪injectFlexFormService(\TYPO3\CMS\Core\Service\FlexFormService $flexFormService)
Definition: FrontendConfigurationManager.php:35
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:614
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager
Definition: AbstractConfigurationManager.php:22
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\overrideSwitchableControllerActions
‪overrideSwitchableControllerActions(array &$frameworkConfiguration, array $switchableControllerActions)
Definition: AbstractConfigurationManager.php:229
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager
Definition: FrontendConfigurationManager.php:27
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$configuration
‪array $configuration
Definition: AbstractConfigurationManager.php:32
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\getContextSpecificFrameworkConfiguration
‪array getContextSpecificFrameworkConfiguration(array $frameworkConfiguration)
Definition: FrontendConfigurationManager.php:105
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\mergeConfigurationIntoFrameworkConfiguration
‪array mergeConfigurationIntoFrameworkConfiguration(array $frameworkConfiguration, array $configuration, $configurationPartName)
Definition: FrontendConfigurationManager.php:200
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\overrideSwitchableControllerActionsFromFlexForm
‪array overrideSwitchableControllerActionsFromFlexForm(array $frameworkConfiguration, array $flexFormConfiguration)
Definition: FrontendConfigurationManager.php:220
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\getPluginConfiguration
‪array getPluginConfiguration($extensionName, $pluginName=null)
Definition: FrontendConfigurationManager.php:58
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\overrideConfigurationFromPlugin
‪array overrideConfigurationFromPlugin(array $frameworkConfiguration)
Definition: FrontendConfigurationManager.php:152
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\overrideConfigurationFromFlexForm
‪array overrideConfigurationFromFlexForm(array $frameworkConfiguration)
Definition: FrontendConfigurationManager.php:173
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:23
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\overrideStoragePidIfStartingPointIsSet
‪array overrideStoragePidIfStartingPointIsSet(array $frameworkConfiguration)
Definition: FrontendConfigurationManager.php:120
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extbase\Configuration
Definition: AbstractConfigurationManager.php:2
‪TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager\getTypoScriptSetup
‪array getTypoScriptSetup()
Definition: FrontendConfigurationManager.php:45
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$extensionName
‪string $extensionName
Definition: AbstractConfigurationManager.php:50