TYPO3 CMS  TYPO3_7-6
ExtensionService.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 
21 {
22  const PLUGIN_TYPE_PLUGIN = 'list_type';
23  const PLUGIN_TYPE_CONTENT_ELEMENT = 'CType';
24 
28  protected $objectManager;
29 
34 
39  protected $targetPidPluginCache = [];
40 
44  public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
45  {
46  $this->objectManager = $objectManager;
47  }
48 
52  public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)
53  {
54  $this->configurationManager = $configurationManager;
55  }
56 
66  public function getPluginNamespace($extensionName, $pluginName)
67  {
68  $pluginSignature = strtolower($extensionName . '_' . $pluginName);
69  $defaultPluginNamespace = 'tx_' . $pluginSignature;
70  $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, $extensionName, $pluginName);
71  if (!isset($frameworkConfiguration['view']['pluginNamespace']) || empty($frameworkConfiguration['view']['pluginNamespace'])) {
72  return $defaultPluginNamespace;
73  }
74  return $frameworkConfiguration['view']['pluginNamespace'];
75  }
76 
90  public function getPluginNameByAction($extensionName, $controllerName, $actionName)
91  {
92  $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
93  // check, whether the current plugin is configured to handle the action
94  if ($extensionName === $frameworkConfiguration['extensionName']) {
95  if (isset($frameworkConfiguration['controllerConfiguration'][$controllerName]) && in_array($actionName, $frameworkConfiguration['controllerConfiguration'][$controllerName]['actions'])) {
96  return $frameworkConfiguration['pluginName'];
97  }
98  }
99  if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'])) {
100  return null;
101  }
102  $pluginNames = [];
103  foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'] as $pluginName => $pluginConfiguration) {
104  if (!is_array($pluginConfiguration['controllers'])) {
105  continue;
106  }
107  foreach ($pluginConfiguration['controllers'] as $pluginControllerName => $pluginControllerActions) {
108  if (strtolower($pluginControllerName) !== strtolower($controllerName)) {
109  continue;
110  }
111  if (in_array($actionName, $pluginControllerActions['actions'])) {
112  $pluginNames[] = $pluginName;
113  }
114  }
115  }
116  if (count($pluginNames) > 1) {
117  throw new \TYPO3\CMS\Extbase\Exception('There is more than one plugin that can handle this request (Extension: "' . $extensionName . '", Controller: "' . $controllerName . '", action: "' . $actionName . '"). Please specify "pluginName" argument', 1280825466);
118  }
119  return !empty($pluginNames) ? $pluginNames[0] : null;
120  }
121 
131  public function isActionCacheable($extensionName, $pluginName, $controllerName, $actionName)
132  {
133  $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, $extensionName, $pluginName);
134  if (isset($frameworkConfiguration['controllerConfiguration'][$controllerName]) && is_array($frameworkConfiguration['controllerConfiguration'][$controllerName]) && is_array($frameworkConfiguration['controllerConfiguration'][$controllerName]['nonCacheableActions']) && in_array($actionName, $frameworkConfiguration['controllerConfiguration'][$controllerName]['nonCacheableActions'])) {
135  return false;
136  }
137  return true;
138  }
139 
152  public function getTargetPidByPlugin($extensionName, $pluginName)
153  {
154  $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, $extensionName, $pluginName);
155  if (!isset($frameworkConfiguration['view']['defaultPid']) || empty($frameworkConfiguration['view']['defaultPid'])) {
156  return null;
157  }
158  $pluginSignature = strtolower($extensionName . '_' . $pluginName);
159  if ($frameworkConfiguration['view']['defaultPid'] === 'auto') {
160  if (!array_key_exists($pluginSignature, $this->targetPidPluginCache)) {
161  $pages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('pid', 'tt_content', 'list_type=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($pluginSignature, 'tt_content') . ' AND CType="list"' . $GLOBALS['TSFE']->sys_page->enableFields('tt_content') . ' AND sys_language_uid=' . $GLOBALS['TSFE']->sys_language_uid, '', '', 2);
162  if (count($pages) > 1) {
163  throw new \TYPO3\CMS\Extbase\Exception('There is more than one "' . $pluginSignature . '" plugin in the current page tree. Please remove one plugin or set the TypoScript configuration "plugin.tx_' . $pluginSignature . '.view.defaultPid" to a fixed page id', 1280773643);
164  }
165  $this->targetPidPluginCache[$pluginSignature] = !empty($pages) ? $pages[0]['pid'] : null;
166  }
167  return $this->targetPidPluginCache[$pluginSignature];
168  }
169  return (int)$frameworkConfiguration['view']['defaultPid'];
170  }
171 
179  public function getDefaultControllerNameByPlugin($extensionName, $pluginName)
180  {
181  if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'])) {
182  return null;
183  }
184  $controllers = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'];
185  return key($controllers);
186  }
187 
196  public function getDefaultActionNameByPluginAndController($extensionName, $pluginName, $controllerName)
197  {
198  if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'][$controllerName]['actions'])) {
199  return null;
200  }
201  $actions = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'][$controllerName]['actions'];
202  return current($actions);
203  }
204 
212  public function getTargetPageTypeByFormat($extensionName, $format)
213  {
214  $targetPageType = 0;
215  $settings = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, $extensionName);
216  $formatToPageTypeMapping = isset($settings['view']['formatToPageTypeMapping']) ? $settings['view']['formatToPageTypeMapping'] : [];
217  if (is_array($formatToPageTypeMapping) && array_key_exists($format, $formatToPageTypeMapping)) {
218  $targetPageType = (int)$formatToPageTypeMapping[$format];
219  }
220  return $targetPageType;
221  }
222 }
getPluginNameByAction($extensionName, $controllerName, $actionName)
injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)
getTargetPidByPlugin($extensionName, $pluginName)
getPluginNamespace($extensionName, $pluginName)
isActionCacheable($extensionName, $pluginName, $controllerName, $actionName)
injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
getTargetPageTypeByFormat($extensionName, $format)
getDefaultActionNameByPluginAndController($extensionName, $pluginName, $controllerName)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
getDefaultControllerNameByPlugin($extensionName, $pluginName)