‪TYPO3CMS  9.5
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 
23 
29 {
30  const ‪PLUGIN_TYPE_PLUGIN = 'list_type';
32 
36  protected ‪$objectManager;
37 
41  protected ‪$configurationManager;
42 
47  protected ‪$targetPidPluginCache = [];
48 
52  public function ‪injectObjectManager(\‪TYPO3\CMS\‪Extbase\Object\ObjectManagerInterface ‪$objectManager)
53  {
54  $this->objectManager = ‪$objectManager;
55  }
56 
61  {
62  $this->configurationManager = ‪$configurationManager;
63  }
64 
74  public function ‪getPluginNamespace($extensionName, $pluginName)
75  {
76  $pluginSignature = strtolower($extensionName . '_' . $pluginName);
77  $defaultPluginNamespace = 'tx_' . $pluginSignature;
78  $frameworkConfiguration = $this->configurationManager->getConfiguration(‪ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, $extensionName, $pluginName);
79  if (!isset($frameworkConfiguration['view']['pluginNamespace']) || empty($frameworkConfiguration['view']['pluginNamespace'])) {
80  return $defaultPluginNamespace;
81  }
82  return $frameworkConfiguration['view']['pluginNamespace'];
83  }
84 
98  public function ‪getPluginNameByAction($extensionName, $controllerName, $actionName)
99  {
100  $frameworkConfiguration = $this->configurationManager->getConfiguration(‪ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
101  // check, whether the current plugin is configured to handle the action
102  if (!empty($frameworkConfiguration['extensionName']) && $extensionName === $frameworkConfiguration['extensionName']) {
103  if (isset($frameworkConfiguration['controllerConfiguration'][$controllerName]) && in_array($actionName, $frameworkConfiguration['controllerConfiguration'][$controllerName]['actions'])) {
104  return $frameworkConfiguration['pluginName'];
105  }
106  }
107  $plugins = ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'] ?? false;
108  if (!$plugins) {
109  return null;
110  }
111  $pluginNames = [];
112  foreach ($plugins as $pluginName => $pluginConfiguration) {
113  foreach ($pluginConfiguration['controllers'] ?? [] as $pluginControllerName => $pluginControllerActions) {
114  if (strtolower($pluginControllerName) !== strtolower($controllerName)) {
115  continue;
116  }
117  if (in_array($actionName, $pluginControllerActions['actions'])) {
118  $pluginNames[] = $pluginName;
119  }
120  }
121  }
122  if (count($pluginNames) > 1) {
123  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);
124  }
125  return !empty($pluginNames) ? $pluginNames[0] : null;
126  }
127 
137  public function ‪isActionCacheable($extensionName, $pluginName, $controllerName, $actionName)
138  {
139  $frameworkConfiguration = $this->configurationManager->getConfiguration(‪ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, $extensionName, $pluginName);
140  if (isset($frameworkConfiguration['controllerConfiguration'][$controllerName]) && is_array($frameworkConfiguration['controllerConfiguration'][$controllerName]) && is_array($frameworkConfiguration['controllerConfiguration'][$controllerName]['nonCacheableActions']) && in_array($actionName, $frameworkConfiguration['controllerConfiguration'][$controllerName]['nonCacheableActions'])) {
141  return false;
142  }
143  return true;
144  }
145 
158  public function ‪getTargetPidByPlugin($extensionName, $pluginName)
159  {
160  $frameworkConfiguration = $this->configurationManager->getConfiguration(‪ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, $extensionName, $pluginName);
161  if (!isset($frameworkConfiguration['view']['defaultPid']) || empty($frameworkConfiguration['view']['defaultPid'])) {
162  return null;
163  }
164  $pluginSignature = strtolower($extensionName . '_' . $pluginName);
165  if ($frameworkConfiguration['view']['defaultPid'] === 'auto') {
166  if (!array_key_exists($pluginSignature, $this->targetPidPluginCache)) {
167  $languageId = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('language', 'id', 0);
168  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
169  ->getQueryBuilderForTable('tt_content');
170  $queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class));
171 
172  $pages = $queryBuilder
173  ->select('pid')
174  ->from('tt_content')
175  ->where(
176  $queryBuilder->expr()->eq(
177  'list_type',
178  $queryBuilder->createNamedParameter($pluginSignature, \PDO::PARAM_STR)
179  ),
180  $queryBuilder->expr()->eq(
181  'CType',
182  $queryBuilder->createNamedParameter('list', \PDO::PARAM_STR)
183  ),
184  $queryBuilder->expr()->eq(
185  'sys_language_uid',
186  $queryBuilder->createNamedParameter($languageId, \PDO::PARAM_INT)
187  )
188  )
189  ->setMaxResults(2)
190  ->execute()
191  ->fetchAll();
192 
193  if (count($pages) > 1) {
194  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);
195  }
196  $this->targetPidPluginCache[$pluginSignature] = !empty($pages) ? $pages[0]['pid'] : null;
197  }
198  return $this->targetPidPluginCache[$pluginSignature];
199  }
200  return (int)$frameworkConfiguration['view']['defaultPid'];
201  }
202 
210  public function ‪getDefaultControllerNameByPlugin($extensionName, $pluginName)
211  {
212  $controllers = ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'] ?? false;
213  return $controllers ? key($controllers) : null;
214  }
215 
224  public function ‪getDefaultActionNameByPluginAndController($extensionName, $pluginName, $controllerName)
225  {
226  $actions = ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'][$controllerName]['actions'] ?? false;
227  return $actions ? current($actions) : null;
228  }
229 
237  public function ‪getTargetPageTypeByFormat($extensionName, $format)
238  {
239  // Legacy location
240  $settings = $this->configurationManager->getConfiguration(‪ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, $extensionName);
241  if (isset($settings['view']['formatToPageTypeMapping']) && is_array($settings['view']['formatToPageTypeMapping'])) {
242  trigger_error('Extension "' . $extensionName . '": Defining settings.view.formatToPageTypeMapping will be removed in TYPO3 10. Move definition to view.formatToPageTypeMapping.', E_USER_DEPRECATED);
243  $formatToPageTypeMapping = $settings['view']['formatToPageTypeMapping'];
244  }
245  // Default behaviour
246  $settings = $this->configurationManager->getConfiguration(‪ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, $extensionName);
247  if (isset($settings['view']['formatToPageTypeMapping']) && is_array($settings['view']['formatToPageTypeMapping'])) {
248  ‪ArrayUtility::mergeRecursiveWithOverrule($formatToPageTypeMapping, $settings['view']['formatToPageTypeMapping']);
249  }
250  return $formatToPageTypeMapping[$format] ?? 0;
251  }
252 }
‪TYPO3\CMS\Extbase\Service\ExtensionService\isActionCacheable
‪bool isActionCacheable($extensionName, $pluginName, $controllerName, $actionName)
Definition: ExtensionService.php:134
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Service\ExtensionService\getPluginNamespace
‪string getPluginNamespace($extensionName, $pluginName)
Definition: ExtensionService.php:71
‪TYPO3\CMS\Extbase\Service\ExtensionService\PLUGIN_TYPE_CONTENT_ELEMENT
‪const PLUGIN_TYPE_CONTENT_ELEMENT
Definition: ExtensionService.php:31
‪TYPO3\CMS\Extbase\Service\ExtensionService\PLUGIN_TYPE_PLUGIN
‪const PLUGIN_TYPE_PLUGIN
Definition: ExtensionService.php:30
‪TYPO3
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:22
‪TYPO3\CMS\Extbase\Service
Definition: CacheService.php:2
‪TYPO3\CMS\Extbase\Service\ExtensionService\injectConfigurationManager
‪injectConfigurationManager(ConfigurationManagerInterface $configurationManager)
Definition: ExtensionService.php:57
‪TYPO3\CMS\Extbase\Service\ExtensionService\injectObjectManager
‪injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
Definition: ExtensionService.php:49
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:614
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:49
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface\CONFIGURATION_TYPE_FRAMEWORK
‪const CONFIGURATION_TYPE_FRAMEWORK
Definition: ConfigurationManagerInterface.php:23
‪TYPO3\CMS\Extbase\Service\ExtensionService\getTargetPidByPlugin
‪int getTargetPidByPlugin($extensionName, $pluginName)
Definition: ExtensionService.php:155
‪TYPO3\CMS\Extbase\Service\ExtensionService\getDefaultControllerNameByPlugin
‪string null getDefaultControllerNameByPlugin($extensionName, $pluginName)
Definition: ExtensionService.php:207
‪TYPO3\CMS\Extbase\Service\ExtensionService\$configurationManager
‪ConfigurationManagerInterface $configurationManager
Definition: ExtensionService.php:39
‪TYPO3\CMS\Extbase\Service\ExtensionService\$targetPidPluginCache
‪array $targetPidPluginCache
Definition: ExtensionService.php:44
‪TYPO3\CMS\Extbase\Service\ExtensionService\getPluginNameByAction
‪string getPluginNameByAction($extensionName, $controllerName, $actionName)
Definition: ExtensionService.php:95
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface\CONFIGURATION_TYPE_SETTINGS
‪const CONFIGURATION_TYPE_SETTINGS
Definition: ConfigurationManagerInterface.php:24
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:23
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Extbase\Service\ExtensionService
Definition: ExtensionService.php:29
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Extbase\Service\ExtensionService\$objectManager
‪TYPO3 CMS Extbase Object ObjectManagerInterface $objectManager
Definition: ExtensionService.php:35
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer
Definition: FrontendRestrictionContainer.php:29
‪TYPO3\CMS\Extbase\Service\ExtensionService\getTargetPageTypeByFormat
‪int getTargetPageTypeByFormat($extensionName, $format)
Definition: ExtensionService.php:234
‪TYPO3\CMS\Extbase\Service\ExtensionService\getDefaultActionNameByPluginAndController
‪string null getDefaultActionNameByPluginAndController($extensionName, $pluginName, $controllerName)
Definition: ExtensionService.php:221