‪TYPO3CMS  ‪main
PageTsConfigLoader.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\EventDispatcher\EventDispatcherInterface;
26 
42 {
43  protected EventDispatcherInterface ‪$eventDispatcher;
44  protected string ‪$globalTsConfig = '';
45 
46  public function ‪__construct(EventDispatcherInterface ‪$eventDispatcher)
47  {
48  trigger_error('Class ' . __CLASS__ . ' will be removed with TYPO3 v13.0. Use PageTsConfigFactory instead.', E_USER_DEPRECATED);
49  $this->eventDispatcher = ‪$eventDispatcher;
50  }
51 
55  public function ‪setGlobalTsConfig(string ‪$globalTsConfig): void
56  {
57  $this->globalTsConfig = ‪$globalTsConfig;
58  }
59 
63  public function ‪load(array $rootLine): string
64  {
65  // Verifying includes, and melt the inclusions together into one string
66  $tsData = $this->‪collect($rootLine);
67  return implode("\n[GLOBAL]\n", $tsData);
68  }
69 
75  public function ‪collect(array $rootLine): array
76  {
77  $tsData = [
78  'global' => ‪$this->globalTsConfig,
79  'default' => ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'] ?? '',
80  ];
81  foreach ($rootLine as $page) {
82  // Can happen when the rootline is given from BE context, we skip this
83  if ((int)$page['uid'] === 0) {
84  continue;
85  }
86  if (trim($page['tsconfig_includes'] ?? '')) {
87  $includeTsConfigFileList = ‪GeneralUtility::trimExplode(',', $page['tsconfig_includes'], true);
88  // Traversing list
89  foreach ($includeTsConfigFileList as $key => $includeTsConfigFile) {
90  if (‪PathUtility::isExtensionPath($includeTsConfigFile)) {
91  [$includeTsConfigFileExtensionKey, $includeTsConfigFilename] = explode(
92  '/',
93  substr($includeTsConfigFile, 4),
94  2
95  );
96  if ((string)$includeTsConfigFileExtensionKey !== ''
97  && ‪ExtensionManagementUtility::isLoaded($includeTsConfigFileExtensionKey)
98  && (string)$includeTsConfigFilename !== ''
99  ) {
100  $extensionPath = ‪ExtensionManagementUtility::extPath($includeTsConfigFileExtensionKey);
101  $includeTsConfigFileAndPath = ‪PathUtility::getCanonicalPath($extensionPath . $includeTsConfigFilename);
102  if (str_starts_with($includeTsConfigFileAndPath, $extensionPath) && file_exists($includeTsConfigFileAndPath)) {
103  $tsData['page_' . $page['uid'] . '_includes_' . $key] = (string)file_get_contents($includeTsConfigFileAndPath);
104  }
105  }
106  }
107  }
108  }
109  $tsData['page_' . $page['uid']] = $page['TSconfig'] ?? '';
110  }
111 
112  $event = $this->eventDispatcher->dispatch(new ‪ModifyLoadedPageTsConfigEvent($tsData, $rootLine));
113 
114  // Apply includes
115  return ‪TypoScriptParser::checkIncludeLines_array($event->getTsConfig());
116  }
117 }
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:916
‪TYPO3\CMS\Core\Utility\PathUtility\getCanonicalPath
‪static string getCanonicalPath(string $path)
Definition: PathUtility.php:364
‪TYPO3\CMS\Core\Utility\PathUtility\isExtensionPath
‪static isExtensionPath(string $path)
Definition: PathUtility.php:117
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:27
‪TYPO3\CMS\Core\Configuration\Loader\PageTsConfigLoader\setGlobalTsConfig
‪setGlobalTsConfig(string $globalTsConfig)
Definition: PageTsConfigLoader.php:55
‪TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
Definition: TypoScriptParser.php:38
‪TYPO3\CMS\Core\Configuration\Loader\PageTsConfigLoader
Definition: PageTsConfigLoader.php:42
‪TYPO3\CMS\Core\Configuration\Loader\PageTsConfigLoader\__construct
‪__construct(EventDispatcherInterface $eventDispatcher)
Definition: PageTsConfigLoader.php:46
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\isLoaded
‪static isLoaded(string $key)
Definition: ExtensionManagementUtility.php:93
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:40
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\extPath
‪static extPath(string $key, string $script='')
Definition: ExtensionManagementUtility.php:120
‪TYPO3\CMS\Core\Configuration\Loader\PageTsConfigLoader\load
‪load(array $rootLine)
Definition: PageTsConfigLoader.php:63
‪TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\checkIncludeLines_array
‪static array checkIncludeLines_array(array $array)
Definition: TypoScriptParser.php:1082
‪TYPO3\CMS\Core\Configuration\Loader\PageTsConfigLoader\$globalTsConfig
‪string $globalTsConfig
Definition: PageTsConfigLoader.php:44
‪TYPO3\CMS\Core\Configuration\Loader
‪TYPO3\CMS\Core\Configuration\Event\ModifyLoadedPageTsConfigEvent
Definition: ModifyLoadedPageTsConfigEvent.php:27
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Configuration\Loader\PageTsConfigLoader\collect
‪collect(array $rootLine)
Definition: PageTsConfigLoader.php:75
‪TYPO3\CMS\Core\Configuration\Loader\PageTsConfigLoader\$eventDispatcher
‪EventDispatcherInterface $eventDispatcher
Definition: PageTsConfigLoader.php:43
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51