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