TYPO3 CMS  TYPO3_8-7
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 
20 
25 {
26  const PLUGIN_TYPE_PLUGIN = 'list_type';
27  const PLUGIN_TYPE_CONTENT_ELEMENT = 'CType';
28 
32  protected $objectManager;
33 
38 
43  protected $targetPidPluginCache = [];
44 
48  public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
49  {
50  $this->objectManager = $objectManager;
51  }
52 
56  public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)
57  {
58  $this->configurationManager = $configurationManager;
59  }
60 
70  public function getPluginNamespace($extensionName, $pluginName)
71  {
72  $pluginSignature = strtolower($extensionName . '_' . $pluginName);
73  $defaultPluginNamespace = 'tx_' . $pluginSignature;
74  $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, $extensionName, $pluginName);
75  if (!isset($frameworkConfiguration['view']['pluginNamespace']) || empty($frameworkConfiguration['view']['pluginNamespace'])) {
76  return $defaultPluginNamespace;
77  }
78  return $frameworkConfiguration['view']['pluginNamespace'];
79  }
80 
94  public function getPluginNameByAction($extensionName, $controllerName, $actionName)
95  {
96  $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
97  // check, whether the current plugin is configured to handle the action
98  if ($extensionName === $frameworkConfiguration['extensionName']) {
99  if (isset($frameworkConfiguration['controllerConfiguration'][$controllerName]) && in_array($actionName, $frameworkConfiguration['controllerConfiguration'][$controllerName]['actions'])) {
100  return $frameworkConfiguration['pluginName'];
101  }
102  }
103  if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'])) {
104  return null;
105  }
106  $pluginNames = [];
107  foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'] as $pluginName => $pluginConfiguration) {
108  if (!is_array($pluginConfiguration['controllers'])) {
109  continue;
110  }
111  foreach ($pluginConfiguration['controllers'] as $pluginControllerName => $pluginControllerActions) {
112  if (strtolower($pluginControllerName) !== strtolower($controllerName)) {
113  continue;
114  }
115  if (in_array($actionName, $pluginControllerActions['actions'])) {
116  $pluginNames[] = $pluginName;
117  }
118  }
119  }
120  if (count($pluginNames) > 1) {
121  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);
122  }
123  return !empty($pluginNames) ? $pluginNames[0] : null;
124  }
125 
135  public function isActionCacheable($extensionName, $pluginName, $controllerName, $actionName)
136  {
137  $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, $extensionName, $pluginName);
138  if (isset($frameworkConfiguration['controllerConfiguration'][$controllerName]) && is_array($frameworkConfiguration['controllerConfiguration'][$controllerName]) && is_array($frameworkConfiguration['controllerConfiguration'][$controllerName]['nonCacheableActions']) && in_array($actionName, $frameworkConfiguration['controllerConfiguration'][$controllerName]['nonCacheableActions'])) {
139  return false;
140  }
141  return true;
142  }
143 
156  public function getTargetPidByPlugin($extensionName, $pluginName)
157  {
158  $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, $extensionName, $pluginName);
159  if (!isset($frameworkConfiguration['view']['defaultPid']) || empty($frameworkConfiguration['view']['defaultPid'])) {
160  return null;
161  }
162  $pluginSignature = strtolower($extensionName . '_' . $pluginName);
163  if ($frameworkConfiguration['view']['defaultPid'] === 'auto') {
164  if (!array_key_exists($pluginSignature, $this->targetPidPluginCache)) {
165  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
166  ->getQueryBuilderForTable('tt_content');
167  $queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class));
168 
169  $pages = $queryBuilder
170  ->select('pid')
171  ->from('tt_content')
172  ->where(
173  $queryBuilder->expr()->eq(
174  'list_type',
175  $queryBuilder->createNamedParameter($pluginSignature, \PDO::PARAM_STR)
176  ),
177  $queryBuilder->expr()->eq(
178  'CType',
179  $queryBuilder->createNamedParameter('list', \PDO::PARAM_STR)
180  ),
181  $queryBuilder->expr()->eq(
182  'sys_language_uid',
183  $queryBuilder->createNamedParameter($GLOBALS['TSFE']->sys_language_uid, \PDO::PARAM_INT)
184  )
185  )
186  ->setMaxResults(2)
187  ->execute()
188  ->fetchAll();
189 
190  if (count($pages) > 1) {
191  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);
192  }
193  $this->targetPidPluginCache[$pluginSignature] = !empty($pages) ? $pages[0]['pid'] : null;
194  }
195  return $this->targetPidPluginCache[$pluginSignature];
196  }
197  return (int)$frameworkConfiguration['view']['defaultPid'];
198  }
199 
207  public function getDefaultControllerNameByPlugin($extensionName, $pluginName)
208  {
209  if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'])) {
210  return null;
211  }
212  $controllers = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'];
213  return key($controllers);
214  }
215 
224  public function getDefaultActionNameByPluginAndController($extensionName, $pluginName, $controllerName)
225  {
226  if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'][$controllerName]['actions'])) {
227  return null;
228  }
229  $actions = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'][$controllerName]['actions'];
230  return current($actions);
231  }
232 
240  public function getTargetPageTypeByFormat($extensionName, $format)
241  {
242  $targetPageType = 0;
243  $settings = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, $extensionName);
244  $formatToPageTypeMapping = isset($settings['view']['formatToPageTypeMapping']) ? $settings['view']['formatToPageTypeMapping'] : [];
245  if (is_array($formatToPageTypeMapping) && array_key_exists($format, $formatToPageTypeMapping)) {
246  $targetPageType = (int)$formatToPageTypeMapping[$format];
247  }
248  return $targetPageType;
249  }
250 }
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)
static makeInstance($className,... $constructorArguments)
getDefaultActionNameByPluginAndController($extensionName, $pluginName, $controllerName)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
getDefaultControllerNameByPlugin($extensionName, $pluginName)