‪TYPO3CMS  10.4
TemplatePaths.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
16 namespace ‪TYPO3\CMS\Fluid\View;
17 
24 
34 class ‪TemplatePaths extends \TYPO3Fluid\Fluid\View\TemplatePaths
35 {
39  protected ‪$templateSource;
40 
45 
50  protected function ‪getExtensionPrivateResourcesPath($extensionKey)
51  {
52  $extensionKey = trim($extensionKey);
53  if ($extensionKey && ‪ExtensionManagementUtility::isLoaded($extensionKey)) {
54  return ‪ExtensionManagementUtility::extPath($extensionKey) . 'Resources/Private/';
55  }
56  return null;
57  }
58 
62  protected function ‪getConfigurationManager()
63  {
64  $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
65  $configurationManager = $objectManager->get(ConfigurationManagerInterface::class);
66  return $configurationManager;
67  }
68 
73  protected function ‪getContextSpecificViewConfiguration($extensionKey)
74  {
75  if (empty($extensionKey)) {
76  return [];
77  }
78 
79  $resources = $this->‪getExtensionPrivateResourcesPath($extensionKey);
80  $paths = [
81  self::CONFIG_TEMPLATEROOTPATHS => [$resources . 'Templates/'],
82  self::CONFIG_PARTIALROOTPATHS => [$resources . 'Partials/'],
83  self::CONFIG_LAYOUTROOTPATHS => [$resources . 'Layouts/']
84  ];
85 
86  $configuredPaths = [];
87  if (!empty($this->templateRootPaths) || !empty($this->partialRootPaths) || !empty($this->layoutRootPaths)) {
88  // The view was configured already
89  $configuredPaths = [
90  self::CONFIG_TEMPLATEROOTPATHS => $this->templateRootPaths,
91  self::CONFIG_PARTIALROOTPATHS => $this->partialRootPaths,
92  self::CONFIG_LAYOUTROOTPATHS => $this->layoutRootPaths,
93  ];
94  } else {
96  $signature = str_replace('_', '', $extensionKey);
97  if ($this->‪isBackendMode() && isset($typoScript['module.']['tx_' . $signature . '.']['view.'])) {
98  $configuredPaths = (array)$typoScript['module.']['tx_' . $signature . '.']['view.'];
99  $configuredPaths = GeneralUtility::removeDotsFromTS($configuredPaths);
100  } elseif ($this->‪isFrontendMode() && isset($typoScript['plugin.']['tx_' . $signature . '.']['view.'])) {
101  $configuredPaths = (array)$typoScript['plugin.']['tx_' . $signature . '.']['view.'];
102  $configuredPaths = GeneralUtility::removeDotsFromTS($configuredPaths);
103  }
104  }
105 
106  if (empty($configuredPaths)) {
107  return $paths;
108  }
109 
110  foreach ($paths as $name => $defaultPaths) {
111  if (!empty($configuredPaths[$name])) {
112  $paths[$name] = array_merge($defaultPaths, ‪ArrayUtility::sortArrayWithIntegerKeys((array)$configuredPaths[$name]));
113  }
114  }
115 
116  return $paths;
117  }
118 
126  public function ‪fillDefaultsByPackageName($packageName)
127  {
128  $this->fillFromConfigurationArray($this->‪getContextSpecificViewConfiguration($packageName));
129  }
130 
136  public function ‪setTemplateRootPaths(array $templateRootPaths)
137  {
138  parent::setTemplateRootPaths(
140  );
141  }
142 
148  public function ‪setLayoutRootPaths(array $layoutRootPaths)
149  {
150  parent::setLayoutRootPaths(
152  );
153  }
154 
160  public function ‪setPartialRootPaths(array $partialRootPaths)
161  {
162  parent::setPartialRootPaths(
164  );
165  }
166 
174  public function ‪getPartialPathAndFilename($partialName)
175  {
176  return parent::getPartialPathAndFilename($partialName);
177  }
178 
184  public function ‪getTemplatePathAndFilename()
185  {
187  }
188 
198  protected function ‪ensureAbsolutePath($reference)
199  {
200  if (!is_array($reference)) {
201  return ‪PathUtility::isAbsolutePath($reference) ? $reference : GeneralUtility::getFileAbsFileName($reference);
202  }
203  foreach ($reference as &$subValue) {
204  $subValue = $this->‪ensureAbsolutePath($subValue);
205  }
206  return $reference;
207  }
208 
212  protected function ‪isBackendMode()
213  {
214  return TYPO3_MODE === 'BE';
215  }
216 
220  protected function ‪isFrontendMode()
221  {
222  return TYPO3_MODE === 'FE';
223  }
224 }
‪TYPO3\CMS\Fluid\View\TemplatePaths\getContextSpecificViewConfiguration
‪array getContextSpecificViewConfiguration($extensionKey)
Definition: TemplatePaths.php:71
‪TYPO3\CMS\Fluid\View\TemplatePaths
Definition: TemplatePaths.php:35
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:24
‪TYPO3\CMS\Fluid\View\TemplatePaths\getExtensionPrivateResourcesPath
‪string null getExtensionPrivateResourcesPath($extensionKey)
Definition: TemplatePaths.php:48
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:28
‪TYPO3\CMS\Fluid\View\TemplatePaths\getTemplatePathAndFilename
‪string getTemplatePathAndFilename()
Definition: TemplatePaths.php:182
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:43
‪TYPO3\CMS\Fluid\View\TemplatePaths\setTemplateRootPaths
‪setTemplateRootPaths(array $templateRootPaths)
Definition: TemplatePaths.php:134
‪TYPO3\CMS\Fluid\View\TemplatePaths\getConfigurationManager
‪ConfigurationManagerInterface getConfigurationManager()
Definition: TemplatePaths.php:60
‪TYPO3\CMS\Fluid\View\TemplatePaths\isBackendMode
‪bool isBackendMode()
Definition: TemplatePaths.php:210
‪TYPO3\CMS\Fluid\View\TemplatePaths\isFrontendMode
‪bool isFrontendMode()
Definition: TemplatePaths.php:218
‪TYPO3\CMS\Fluid\View\TemplatePaths\fillDefaultsByPackageName
‪fillDefaultsByPackageName($packageName)
Definition: TemplatePaths.php:124
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface\getConfiguration
‪array getConfiguration(string $configurationType, ?string $extensionName=null, ?string $pluginName=null)
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface\CONFIGURATION_TYPE_FULL_TYPOSCRIPT
‪const CONFIGURATION_TYPE_FULL_TYPOSCRIPT
Definition: ConfigurationManagerInterface.php:31
‪TYPO3\CMS\Core\Utility\PathUtility\isAbsolutePath
‪static bool isAbsolutePath($path)
Definition: PathUtility.php:223
‪TYPO3\CMS\Fluid\View\TemplatePaths\$templatePathAndFilename
‪string $templatePathAndFilename
Definition: TemplatePaths.php:42
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪TYPO3\CMS\Fluid\View\TemplatePaths\$templateSource
‪string $templateSource
Definition: TemplatePaths.php:38
‪TYPO3\CMS\Fluid\View\TemplatePaths\getPartialPathAndFilename
‪string getPartialPathAndFilename($partialName)
Definition: TemplatePaths.php:172
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\extPath
‪static string extPath($key, $script='')
Definition: ExtensionManagementUtility.php:127
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Fluid\View\TemplatePaths\setLayoutRootPaths
‪setLayoutRootPaths(array $layoutRootPaths)
Definition: TemplatePaths.php:146
‪TYPO3\CMS\Fluid\View\TemplatePaths\setPartialRootPaths
‪setPartialRootPaths(array $partialRootPaths)
Definition: TemplatePaths.php:158
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\isLoaded
‪static bool isLoaded($key)
Definition: ExtensionManagementUtility.php:114
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:28
‪TYPO3\CMS\Fluid\View
Definition: AbstractTemplateView.php:16
‪TYPO3\CMS\Core\Utility\ArrayUtility\sortArrayWithIntegerKeys
‪static array sortArrayWithIntegerKeys(array $array)
Definition: ArrayUtility.php:865
‪TYPO3\CMS\Fluid\View\TemplatePaths\ensureAbsolutePath
‪string ensureAbsolutePath($reference)
Definition: TemplatePaths.php:196