TYPO3  7.6
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 
23 {
27  protected $flexFormService;
28 
32  public function injectFlexFormService(\TYPO3\CMS\Extbase\Service\FlexFormService $flexFormService)
33  {
34  $this->flexFormService = $flexFormService;
35  }
36 
42  public function getTypoScriptSetup()
43  {
44  return $GLOBALS['TSFE']->tmpl->setup;
45  }
46 
56  {
57  $setup = $this->getTypoScriptSetup();
58  $pluginConfiguration = array();
59  if (is_array($setup['plugin.']['tx_' . strtolower($extensionName) . '.'])) {
60  $pluginConfiguration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['plugin.']['tx_' . strtolower($extensionName) . '.']);
61  }
62  if ($pluginName !== null) {
63  $pluginSignature = strtolower($extensionName . '_' . $pluginName);
64  if (is_array($setup['plugin.']['tx_' . $pluginSignature . '.'])) {
65  \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule(
66  $pluginConfiguration,
67  $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['plugin.']['tx_' . $pluginSignature . '.'])
68  );
69  }
70  }
71  return $pluginConfiguration;
72  }
73 
86  {
87  $switchableControllerActions = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'];
88  if (!is_array($switchableControllerActions)) {
89  $switchableControllerActions = array();
90  }
91  return $switchableControllerActions;
92  }
93 
102  protected function getContextSpecificFrameworkConfiguration(array $frameworkConfiguration)
103  {
104  $frameworkConfiguration = $this->overrideStoragePidIfStartingPointIsSet($frameworkConfiguration);
105  $frameworkConfiguration = $this->overrideConfigurationFromPlugin($frameworkConfiguration);
106  $frameworkConfiguration = $this->overrideConfigurationFromFlexForm($frameworkConfiguration);
107  return $frameworkConfiguration;
108  }
109 
117  protected function overrideStoragePidIfStartingPointIsSet(array $frameworkConfiguration)
118  {
119  $pages = $this->contentObject->data['pages'];
120  if (is_string($pages) && $pages !== '') {
121  $list = array();
122  if ($this->contentObject->data['recursive'] > 0) {
123  $explodedPages = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $pages);
124  foreach ($explodedPages as $pid) {
125  $list[] = $this->contentObject->getTreeList($pid, $this->contentObject->data['recursive']);
126  }
127  }
128  if (!empty($list)) {
129  $pages = $pages . ',' . implode(',', $list);
130  }
131  \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($frameworkConfiguration, array(
132  'persistence' => array(
133  'storagePid' => $pages
134  )
135  ));
136  }
137  return $frameworkConfiguration;
138  }
139 
146  protected function overrideConfigurationFromPlugin(array $frameworkConfiguration)
147  {
148  $setup = $this->getTypoScriptSetup();
149  $pluginSignature = strtolower($frameworkConfiguration['extensionName'] . '_' . $frameworkConfiguration['pluginName']);
150  $pluginConfiguration = $setup['plugin.']['tx_' . $pluginSignature . '.'];
151  if (is_array($pluginConfiguration)) {
152  $pluginConfiguration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($pluginConfiguration);
153  $frameworkConfiguration = $this->mergeConfigurationIntoFrameworkConfiguration($frameworkConfiguration, $pluginConfiguration, 'settings');
154  $frameworkConfiguration = $this->mergeConfigurationIntoFrameworkConfiguration($frameworkConfiguration, $pluginConfiguration, 'persistence');
155  $frameworkConfiguration = $this->mergeConfigurationIntoFrameworkConfiguration($frameworkConfiguration, $pluginConfiguration, 'view');
156  }
157  return $frameworkConfiguration;
158  }
159 
167  protected function overrideConfigurationFromFlexForm(array $frameworkConfiguration)
168  {
169  $flexFormConfiguration = $this->contentObject->data['pi_flexform'];
170  if (is_string($flexFormConfiguration)) {
171  if ($flexFormConfiguration !== '') {
172  $flexFormConfiguration = $this->flexFormService->convertFlexFormContentToArray($flexFormConfiguration);
173  } else {
174  $flexFormConfiguration = array();
175  }
176  }
177  if (is_array($flexFormConfiguration) && !empty($flexFormConfiguration)) {
178  $frameworkConfiguration = $this->mergeConfigurationIntoFrameworkConfiguration($frameworkConfiguration, $flexFormConfiguration, 'settings');
179  $frameworkConfiguration = $this->mergeConfigurationIntoFrameworkConfiguration($frameworkConfiguration, $flexFormConfiguration, 'persistence');
180  $frameworkConfiguration = $this->mergeConfigurationIntoFrameworkConfiguration($frameworkConfiguration, $flexFormConfiguration, 'view');
181  $frameworkConfiguration = $this->overrideSwitchableControllerActionsFromFlexForm($frameworkConfiguration, $flexFormConfiguration);
182  }
183  return $frameworkConfiguration;
184  }
185 
194  protected function mergeConfigurationIntoFrameworkConfiguration(array $frameworkConfiguration, array $configuration, $configurationPartName)
195  {
196  if (is_array($configuration[$configurationPartName])) {
197  if (is_array($frameworkConfiguration[$configurationPartName])) {
198  \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($frameworkConfiguration[$configurationPartName], $configuration[$configurationPartName]);
199  } else {
200  $frameworkConfiguration[$configurationPartName] = $configuration[$configurationPartName];
201  }
202  }
203  return $frameworkConfiguration;
204  }
205 
214  protected function overrideSwitchableControllerActionsFromFlexForm(array $frameworkConfiguration, array $flexFormConfiguration)
215  {
216  if (!isset($flexFormConfiguration['switchableControllerActions']) || is_array($flexFormConfiguration['switchableControllerActions'])) {
217  return $frameworkConfiguration;
218  }
219  // As "," is the flexForm field value delimiter, we need to use ";" as in-field delimiter. That's why we need to replace ; by , first.
220  // The expected format is: "Controller1->action2;Controller2->action3;Controller2->action1"
221  $switchableControllerActionPartsFromFlexForm = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', str_replace(';', ',', $flexFormConfiguration['switchableControllerActions']), true);
222  $newSwitchableControllerActionsFromFlexForm = array();
223  foreach ($switchableControllerActionPartsFromFlexForm as $switchableControllerActionPartFromFlexForm) {
224  list($controller, $action) = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('->', $switchableControllerActionPartFromFlexForm);
225  if (empty($controller) || empty($action)) {
226  throw new \TYPO3\CMS\Extbase\Configuration\Exception\ParseErrorException('Controller or action were empty when overriding switchableControllerActions from flexForm.', 1257146403);
227  }
228  $newSwitchableControllerActionsFromFlexForm[$controller][] = $action;
229  }
230  if (!empty($newSwitchableControllerActionsFromFlexForm)) {
231  $this->overrideSwitchableControllerActions($frameworkConfiguration, $newSwitchableControllerActionsFromFlexForm);
232  }
233  return $frameworkConfiguration;
234  }
235 
243  protected function getRecursiveStoragePids($storagePid, $recursionDepth = 0)
244  {
245  if ($recursionDepth <= 0) {
246  return $storagePid;
247  }
248 
249  $recursiveStoragePids = '';
250  $storagePids = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $storagePid);
251  foreach ($storagePids as $startPid) {
252  $pids = $this->getContentObject()->getTreeList($startPid, $recursionDepth, 0);
253  if ((string)$pids !== '') {
254  $recursiveStoragePids .= $pids . ',';
255  }
256  }
257  return rtrim($recursiveStoragePids, ',');
258  }
259 }