‪TYPO3CMS  10.4
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 
39 {
43  protected ‪$eventDispatcher;
44 
45  public function ‪__construct(EventDispatcherInterface ‪$eventDispatcher)
46  {
47  $this->eventDispatcher = ‪$eventDispatcher;
48  }
49 
55  public function ‪load(array $rootLine): string
56  {
57  // Verifying includes, and melt the inclusions together into one string
58  $tsData = $this->‪collect($rootLine);
59  return implode("\n[GLOBAL]\n", $tsData);
60  }
61 
69  public function ‪collect(array $rootLine): array
70  {
71  $tsData = [
72  'default' => ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'] ?? ''
73  ];
74  foreach ($rootLine as $page) {
75  // Can happen when the rootline is given from BE context, we skip this
76  if ((int)$page['uid'] === 0) {
77  continue;
78  }
79  if (trim($page['tsconfig_includes'] ?? '')) {
80  $includeTsConfigFileList = ‪GeneralUtility::trimExplode(',', $page['tsconfig_includes'], true);
81  // Traversing list
82  foreach ($includeTsConfigFileList as $key => $includeTsConfigFile) {
83  if (strpos($includeTsConfigFile, 'EXT:') === 0) {
84  [$includeTsConfigFileExtensionKey, $includeTsConfigFilename] = explode(
85  '/',
86  substr($includeTsConfigFile, 4),
87  2
88  );
89  if ((string)$includeTsConfigFileExtensionKey !== ''
90  && ‪ExtensionManagementUtility::isLoaded($includeTsConfigFileExtensionKey)
91  && (string)$includeTsConfigFilename !== ''
92  ) {
93  $extensionPath = ‪ExtensionManagementUtility::extPath($includeTsConfigFileExtensionKey);
94  $includeTsConfigFileAndPath = ‪PathUtility::getCanonicalPath($extensionPath . $includeTsConfigFilename);
95  if (strpos($includeTsConfigFileAndPath, $extensionPath) === 0 && file_exists($includeTsConfigFileAndPath)) {
96  $tsData['page_' . $page['uid'] . '_includes_' . $key] = (string)file_get_contents($includeTsConfigFileAndPath);
97  }
98  }
99  }
100  }
101  }
102  $tsData['page_' . $page['uid']] = $page['TSconfig'] ?? '';
103  }
104 
105  $event = $this->eventDispatcher->dispatch(new ModifyLoadedPageTsConfigEvent($tsData, $rootLine));
106 
107  // Apply includes
108  return ‪TypoScriptParser::checkIncludeLines_array($event->getTsConfig());
109  }
110 }
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:24
‪TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
Definition: TypoScriptParser.php:37
‪TYPO3\CMS\Core\Configuration\Loader\PageTsConfigLoader
Definition: PageTsConfigLoader.php:39
‪TYPO3\CMS\Core\Utility\PathUtility\getCanonicalPath
‪static string getCanonicalPath($path)
Definition: PathUtility.php:307
‪TYPO3\CMS\Core\Configuration\Loader\PageTsConfigLoader\__construct
‪__construct(EventDispatcherInterface $eventDispatcher)
Definition: PageTsConfigLoader.php:44
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:43
‪TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\checkIncludeLines_array
‪static array checkIncludeLines_array(array $array)
Definition: TypoScriptParser.php:1190
‪TYPO3\CMS\Core\Configuration\Loader
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪TYPO3\CMS\Core\Configuration\Event\ModifyLoadedPageTsConfigEvent
Definition: ModifyLoadedPageTsConfigEvent.php:24
‪TYPO3\CMS\Core\Configuration\Loader\PageTsConfigLoader\collect
‪array collect(array $rootLine)
Definition: PageTsConfigLoader.php:68
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Configuration\Loader\PageTsConfigLoader\$eventDispatcher
‪EventDispatcherInterface $eventDispatcher
Definition: PageTsConfigLoader.php:42
‪TYPO3\CMS\Core\Configuration\Loader\PageTsConfigLoader\load
‪string load(array $rootLine)
Definition: PageTsConfigLoader.php:54
‪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\Core\Utility\ExtensionManagementUtility\isLoaded
‪static bool isLoaded($key)
Definition: ExtensionManagementUtility.php:114