TYPO3 CMS  TYPO3_8-7
TemplatePaths.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Fluid\View;
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 
31 class TemplatePaths extends \TYPO3Fluid\Fluid\View\TemplatePaths
32 {
36  protected $templateSource;
37 
42 
47  protected function getExtensionPrivateResourcesPath($extensionKey)
48  {
49  $extensionKey = trim($extensionKey);
50  if ($extensionKey && ExtensionManagementUtility::isLoaded($extensionKey)) {
51  return ExtensionManagementUtility::extPath($extensionKey) . 'Resources/Private/';
52  }
53  return null;
54  }
55 
59  protected function getConfigurationManager()
60  {
61  $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
62  $configurationManager = $objectManager->get(ConfigurationManagerInterface::class);
63  return $configurationManager;
64  }
65 
70  protected function getContextSpecificViewConfiguration($extensionKey)
71  {
72  if (empty($extensionKey)) {
73  return [];
74  }
75 
76  $resources = $this->getExtensionPrivateResourcesPath($extensionKey);
77  $paths = [
78  self::CONFIG_TEMPLATEROOTPATHS => [$resources . 'Templates/'],
79  self::CONFIG_PARTIALROOTPATHS => [$resources . 'Partials/'],
80  self::CONFIG_LAYOUTROOTPATHS => [$resources . 'Layouts/']
81  ];
82 
83  $configuredPaths = [];
84  if (!empty($this->templateRootPaths) || !empty($this->partialRootPaths) || !empty($this->layoutRootPaths)) {
85  // The view was configured already
86  $configuredPaths = [
87  self::CONFIG_TEMPLATEROOTPATHS => $this->templateRootPaths,
88  self::CONFIG_PARTIALROOTPATHS => $this->partialRootPaths,
89  self::CONFIG_LAYOUTROOTPATHS => $this->layoutRootPaths,
90  ];
91  } else {
93  $signature = str_replace('_', '', $extensionKey);
94  if ($this->isBackendMode() && isset($typoScript['module.']['tx_' . $signature . '.']['view.'])) {
95  $configuredPaths = (array)$typoScript['module.']['tx_' . $signature . '.']['view.'];
96  $configuredPaths = GeneralUtility::removeDotsFromTS($configuredPaths);
97  } elseif ($this->isFrontendMode() && isset($typoScript['plugin.']['tx_' . $signature . '.']['view.'])) {
98  $configuredPaths = (array)$typoScript['plugin.']['tx_' . $signature . '.']['view.'];
99  $configuredPaths = GeneralUtility::removeDotsFromTS($configuredPaths);
100  }
101  }
102 
103  if (empty($configuredPaths)) {
104  return $paths;
105  }
106 
107  foreach ($paths as $name => $defaultPaths) {
108  if (!empty($configuredPaths[$name])) {
109  $paths[$name] = array_merge($defaultPaths, ArrayUtility::sortArrayWithIntegerKeys((array)$configuredPaths[$name]));
110  }
111  }
112 
113  return $paths;
114  }
115 
123  public function fillDefaultsByPackageName($packageName)
124  {
125  $this->fillFromConfigurationArray($this->getContextSpecificViewConfiguration($packageName));
126  }
127 
133  public function setTemplateRootPaths(array $templateRootPaths)
134  {
135  parent::setTemplateRootPaths(
136  ArrayUtility::sortArrayWithIntegerKeys($templateRootPaths)
137  );
138  }
139 
145  public function setLayoutRootPaths(array $layoutRootPaths)
146  {
147  parent::setLayoutRootPaths(
149  );
150  }
151 
157  public function setPartialRootPaths(array $partialRootPaths)
158  {
159  parent::setPartialRootPaths(
160  ArrayUtility::sortArrayWithIntegerKeys($partialRootPaths)
161  );
162  }
163 
171  public function getPartialPathAndFilename($partialName)
172  {
173  return parent::getPartialPathAndFilename($partialName);
174  }
175 
181  public function getTemplatePathAndFilename()
182  {
184  }
185 
195  protected function ensureAbsolutePath($reference)
196  {
197  if (!is_array($reference)) {
198  return PathUtility::isAbsolutePath($reference) ? $reference : GeneralUtility::getFileAbsFileName($reference);
199  }
200  foreach ($reference as &$subValue) {
201  $subValue = $this->ensureAbsolutePath($subValue);
202  }
203  return $reference;
204  }
205 
209  protected function isBackendMode()
210  {
211  return TYPO3_MODE === 'BE';
212  }
213 
217  protected function isFrontendMode()
218  {
219  return TYPO3_MODE === 'FE';
220  }
221 }
setPartialRootPaths(array $partialRootPaths)
static getFileAbsFileName($filename, $_=null, $_2=null)
getExtensionPrivateResourcesPath($extensionKey)
static makeInstance($className,... $constructorArguments)
setLayoutRootPaths(array $layoutRootPaths)
setTemplateRootPaths(array $templateRootPaths)
static sortArrayWithIntegerKeys(array $array)
getContextSpecificViewConfiguration($extensionKey)