‪TYPO3CMS  9.5
TemplatePaths.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 
33 class ‪TemplatePaths extends \TYPO3Fluid\Fluid\View\TemplatePaths
34 {
38  protected ‪$templateSource;
39 
44 
49  protected function ‪getExtensionPrivateResourcesPath($extensionKey)
50  {
51  $extensionKey = trim($extensionKey);
52  if ($extensionKey && ‪ExtensionManagementUtility::isLoaded($extensionKey)) {
53  return ‪ExtensionManagementUtility::extPath($extensionKey) . 'Resources/Private/';
54  }
55  return null;
56  }
57 
61  protected function ‪getConfigurationManager()
62  {
63  $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
64  $configurationManager = $objectManager->get(ConfigurationManagerInterface::class);
65  return $configurationManager;
66  }
67 
72  protected function ‪getContextSpecificViewConfiguration($extensionKey)
73  {
74  if (empty($extensionKey)) {
75  return [];
76  }
77 
78  $resources = $this->‪getExtensionPrivateResourcesPath($extensionKey);
79  $paths = [
80  self::CONFIG_TEMPLATEROOTPATHS => [$resources . 'Templates/'],
81  self::CONFIG_PARTIALROOTPATHS => [$resources . 'Partials/'],
82  self::CONFIG_LAYOUTROOTPATHS => [$resources . 'Layouts/']
83  ];
84 
85  $configuredPaths = [];
86  if (!empty($this->templateRootPaths) || !empty($this->partialRootPaths) || !empty($this->layoutRootPaths)) {
87  // The view was configured already
88  $configuredPaths = [
89  self::CONFIG_TEMPLATEROOTPATHS => $this->templateRootPaths,
90  self::CONFIG_PARTIALROOTPATHS => $this->partialRootPaths,
91  self::CONFIG_LAYOUTROOTPATHS => $this->layoutRootPaths,
92  ];
93  } else {
95  $signature = str_replace('_', '', $extensionKey);
96  if ($this->‪isBackendMode() && isset($typoScript['module.']['tx_' . $signature . '.']['view.'])) {
97  $configuredPaths = (array)$typoScript['module.']['tx_' . $signature . '.']['view.'];
98  $configuredPaths = GeneralUtility::removeDotsFromTS($configuredPaths);
99  } elseif ($this->‪isFrontendMode() && isset($typoScript['plugin.']['tx_' . $signature . '.']['view.'])) {
100  $configuredPaths = (array)$typoScript['plugin.']['tx_' . $signature . '.']['view.'];
101  $configuredPaths = GeneralUtility::removeDotsFromTS($configuredPaths);
102  }
103  }
104 
105  if (empty($configuredPaths)) {
106  return $paths;
107  }
108 
109  foreach ($paths as $name => $defaultPaths) {
110  if (!empty($configuredPaths[$name])) {
111  $paths[$name] = array_merge($defaultPaths, ‪ArrayUtility::sortArrayWithIntegerKeys((array)$configuredPaths[$name]));
112  }
113  }
114 
115  return $paths;
116  }
117 
125  public function ‪fillDefaultsByPackageName($packageName)
126  {
127  $this->fillFromConfigurationArray($this->‪getContextSpecificViewConfiguration($packageName));
128  }
129 
135  public function ‪setTemplateRootPaths(array $templateRootPaths)
136  {
137  parent::setTemplateRootPaths(
139  );
140  }
141 
147  public function ‪setLayoutRootPaths(array $layoutRootPaths)
148  {
149  parent::setLayoutRootPaths(
151  );
152  }
153 
159  public function ‪setPartialRootPaths(array $partialRootPaths)
160  {
161  parent::setPartialRootPaths(
163  );
164  }
165 
173  public function ‪getPartialPathAndFilename($partialName)
174  {
175  return parent::getPartialPathAndFilename($partialName);
176  }
177 
183  public function ‪getTemplatePathAndFilename()
184  {
186  }
187 
197  protected function ‪ensureAbsolutePath($reference)
198  {
199  if (!is_array($reference)) {
200  return ‪PathUtility::isAbsolutePath($reference) ? $reference : GeneralUtility::getFileAbsFileName($reference);
201  }
202  foreach ($reference as &$subValue) {
203  $subValue = $this->‪ensureAbsolutePath($subValue);
204  }
205  return $reference;
206  }
207 
211  protected function ‪isBackendMode()
212  {
213  return TYPO3_MODE === 'BE';
214  }
215 
219  protected function ‪isFrontendMode()
220  {
221  return TYPO3_MODE === 'FE';
222  }
223 }
‪TYPO3\CMS\Fluid\View\TemplatePaths\getContextSpecificViewConfiguration
‪array getContextSpecificViewConfiguration($extensionKey)
Definition: TemplatePaths.php:70
‪TYPO3\CMS\Fluid\View\TemplatePaths
Definition: TemplatePaths.php:34
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:23
‪TYPO3\CMS\Fluid\View\TemplatePaths\getExtensionPrivateResourcesPath
‪string null getExtensionPrivateResourcesPath($extensionKey)
Definition: TemplatePaths.php:47
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:22
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface\getConfiguration
‪array getConfiguration($configurationType, $extensionName=null, $pluginName=null)
‪TYPO3\CMS\Fluid\View\TemplatePaths\getTemplatePathAndFilename
‪string getTemplatePathAndFilename()
Definition: TemplatePaths.php:181
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:36
‪TYPO3\CMS\Fluid\View\TemplatePaths\setTemplateRootPaths
‪setTemplateRootPaths(array $templateRootPaths)
Definition: TemplatePaths.php:133
‪TYPO3\CMS\Fluid\View\TemplatePaths\getConfigurationManager
‪ConfigurationManagerInterface getConfigurationManager()
Definition: TemplatePaths.php:59
‪TYPO3\CMS\Fluid\View\TemplatePaths\isBackendMode
‪bool isBackendMode()
Definition: TemplatePaths.php:209
‪TYPO3\CMS\Fluid\View\TemplatePaths\isFrontendMode
‪bool isFrontendMode()
Definition: TemplatePaths.php:217
‪TYPO3\CMS\Fluid\View\TemplatePaths\fillDefaultsByPackageName
‪fillDefaultsByPackageName($packageName)
Definition: TemplatePaths.php:123
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\isLoaded
‪static bool isLoaded($key, $exitOnError=null)
Definition: ExtensionManagementUtility.php:115
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface\CONFIGURATION_TYPE_FULL_TYPOSCRIPT
‪const CONFIGURATION_TYPE_FULL_TYPOSCRIPT
Definition: ConfigurationManagerInterface.php:25
‪TYPO3\CMS\Core\Utility\PathUtility\isAbsolutePath
‪static bool isAbsolutePath($path)
Definition: PathUtility.php:222
‪TYPO3\CMS\Fluid\View\TemplatePaths\$templatePathAndFilename
‪string $templatePathAndFilename
Definition: TemplatePaths.php:41
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:23
‪TYPO3\CMS\Fluid\View\TemplatePaths\$templateSource
‪string $templateSource
Definition: TemplatePaths.php:37
‪TYPO3\CMS\Fluid\View\TemplatePaths\getPartialPathAndFilename
‪string getPartialPathAndFilename($partialName)
Definition: TemplatePaths.php:171
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\extPath
‪static string extPath($key, $script='')
Definition: ExtensionManagementUtility.php:149
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Fluid\View\TemplatePaths\setLayoutRootPaths
‪setLayoutRootPaths(array $layoutRootPaths)
Definition: TemplatePaths.php:145
‪TYPO3\CMS\Fluid\View\TemplatePaths\setPartialRootPaths
‪setPartialRootPaths(array $partialRootPaths)
Definition: TemplatePaths.php:157
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:25
‪TYPO3\CMS\Fluid\View
Definition: AbstractTemplateView.php:2
‪TYPO3\CMS\Core\Utility\ArrayUtility\sortArrayWithIntegerKeys
‪static array sortArrayWithIntegerKeys(array $array)
Definition: ArrayUtility.php:793
‪TYPO3\CMS\Fluid\View\TemplatePaths\ensureAbsolutePath
‪string ensureAbsolutePath($reference)
Definition: TemplatePaths.php:195