‪TYPO3CMS  11.5
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 
18 use Psr\Http\Message\ServerRequestInterface;
26 
36 class ‪TemplatePaths extends \TYPO3Fluid\Fluid\View\TemplatePaths
37 {
41  protected ‪$templateSource;
42 
47 
52  protected function ‪getExtensionPrivateResourcesPath($extensionKey)
53  {
54  $extensionKey = trim($extensionKey);
55  if ($extensionKey && ‪ExtensionManagementUtility::isLoaded($extensionKey)) {
56  return ‪ExtensionManagementUtility::extPath($extensionKey) . 'Resources/Private/';
57  }
58  return null;
59  }
60 
64  protected function ‪getConfigurationManager()
65  {
66  return GeneralUtility::makeInstance(ConfigurationManager::class);
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  $configured = ‪ArrayUtility::sortArrayWithIntegerKeys((array)$configuredPaths[$name]);
113  // calculate implicit default paths which have not been explicitly configured
114  $implicitDefaultPaths = array_diff($defaultPaths, $configured);
115  // prepend implicit default paths (which have not been found in configured paths), as fallbacks
116  $paths[$name] = array_merge($implicitDefaultPaths, $configured);
117  }
118  }
119 
120  return $paths;
121  }
122 
130  public function ‪fillDefaultsByPackageName($packageName)
131  {
132  $this->fillFromConfigurationArray($this->‪getContextSpecificViewConfiguration($packageName));
133  }
134 
140  public function ‪setTemplateRootPaths(array $templateRootPaths)
141  {
142  parent::setTemplateRootPaths(
144  );
145  }
146 
152  public function ‪setLayoutRootPaths(array $layoutRootPaths)
153  {
154  parent::setLayoutRootPaths(
156  );
157  }
158 
164  public function ‪setPartialRootPaths(array $partialRootPaths)
165  {
166  parent::setPartialRootPaths(
168  );
169  }
170 
176  public function ‪getTemplatePathAndFilename()
177  {
179  }
180 
190  protected function ‪ensureAbsolutePath($reference)
191  {
192  if (!is_array($reference)) {
193  return ‪PathUtility::isAbsolutePath($reference) ? $reference : GeneralUtility::getFileAbsFileName($reference);
194  }
195  foreach ($reference as &$subValue) {
196  $subValue = $this->‪ensureAbsolutePath($subValue);
197  }
198  return $reference;
199  }
200 
204  protected function ‪isBackendMode(): bool
205  {
206  return (‪$GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
207  && ‪ApplicationType::fromRequest(‪$GLOBALS['TYPO3_REQUEST'])->isBackend();
208  }
209 
213  protected function ‪isFrontendMode(): bool
214  {
215  return (‪$GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
216  && ‪ApplicationType::fromRequest(‪$GLOBALS['TYPO3_REQUEST'])->isFrontend();
217  }
218 }
‪TYPO3\CMS\Fluid\View\TemplatePaths\getContextSpecificViewConfiguration
‪array getContextSpecificViewConfiguration($extensionKey)
Definition: TemplatePaths.php:71
‪TYPO3\CMS\Core\Http\ApplicationType\fromRequest
‪static static fromRequest(ServerRequestInterface $request)
Definition: ApplicationType.php:62
‪TYPO3\CMS\Fluid\View\TemplatePaths
Definition: TemplatePaths.php:37
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:25
‪TYPO3\CMS\Fluid\View\TemplatePaths\getExtensionPrivateResourcesPath
‪string null getExtensionPrivateResourcesPath($extensionKey)
Definition: TemplatePaths.php:50
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManager\getConfiguration
‪array getConfiguration(string $configurationType, string $extensionName=null, string $pluginName=null)
Definition: ConfigurationManager.php:101
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:28
‪TYPO3\CMS\Fluid\View\TemplatePaths\getTemplatePathAndFilename
‪string getTemplatePathAndFilename()
Definition: TemplatePaths.php:174
‪TYPO3\CMS\Core\Http\ApplicationType
Definition: ApplicationType.php:52
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:43
‪TYPO3\CMS\Fluid\View\TemplatePaths\setTemplateRootPaths
‪setTemplateRootPaths(array $templateRootPaths)
Definition: TemplatePaths.php:138
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManager
Definition: ConfigurationManager.php:33
‪TYPO3\CMS\Fluid\View\TemplatePaths\isBackendMode
‪bool isBackendMode()
Definition: TemplatePaths.php:202
‪TYPO3\CMS\Fluid\View\TemplatePaths\isFrontendMode
‪bool isFrontendMode()
Definition: TemplatePaths.php:211
‪TYPO3\CMS\Fluid\View\TemplatePaths\fillDefaultsByPackageName
‪fillDefaultsByPackageName($packageName)
Definition: TemplatePaths.php:128
‪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:296
‪TYPO3\CMS\Fluid\View\TemplatePaths\$templatePathAndFilename
‪string $templatePathAndFilename
Definition: TemplatePaths.php:44
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪TYPO3\CMS\Fluid\View\TemplatePaths\$templateSource
‪string $templateSource
Definition: TemplatePaths.php:40
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\extPath
‪static string extPath($key, $script='')
Definition: ExtensionManagementUtility.php:142
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Fluid\View\TemplatePaths\setLayoutRootPaths
‪setLayoutRootPaths(array $layoutRootPaths)
Definition: TemplatePaths.php:150
‪TYPO3\CMS\Fluid\View\TemplatePaths\setPartialRootPaths
‪setPartialRootPaths(array $partialRootPaths)
Definition: TemplatePaths.php:162
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\isLoaded
‪static bool isLoaded($key)
Definition: ExtensionManagementUtility.php:114
‪TYPO3\CMS\Fluid\View
Definition: AbstractTemplateView.php:16
‪TYPO3\CMS\Core\Utility\ArrayUtility\sortArrayWithIntegerKeys
‪static array sortArrayWithIntegerKeys(array $array)
Definition: ArrayUtility.php:873
‪TYPO3\CMS\Fluid\View\TemplatePaths\getConfigurationManager
‪ConfigurationManager getConfigurationManager()
Definition: TemplatePaths.php:62
‪TYPO3\CMS\Fluid\View\TemplatePaths\ensureAbsolutePath
‪string ensureAbsolutePath($reference)
Definition: TemplatePaths.php:188