‪TYPO3CMS  9.5
PageTitleProviderManager.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
23 
28 {
32  private ‪$pageTitleCache = [];
33 
39  public function ‪getTitle(): string
40  {
41  $pageTitle = '';
42 
43  $titleProviders = $this->‪getPageTitleProviderConfiguration();
44  $titleProviders = $this->‪setProviderOrder($titleProviders);
45 
46  $orderedTitleProviders = GeneralUtility::makeInstance(DependencyOrderingService::class)
47  ->orderByDependencies($titleProviders);
48 
49  foreach ($orderedTitleProviders as $provider => $configuration) {
50  if (class_exists($configuration['provider']) && is_subclass_of($configuration['provider'], PageTitleProviderInterface::class)) {
52  $titleProviderObject = GeneralUtility::makeInstance($configuration['provider']);
53  if (($pageTitle = $titleProviderObject->getTitle())
54  || ($pageTitle = $this->pageTitleCache[$configuration['provider']] ?? '') !== ''
55  ) {
56  $this->pageTitleCache[$configuration['provider']] = $pageTitle;
57  break;
58  }
59  }
60  }
61 
62  return $pageTitle;
63  }
64 
69  public function ‪getPageTitleCache(): array
70  {
72  }
73 
78  public function ‪setPageTitleCache(array ‪$pageTitleCache): void
79  {
80  $this->pageTitleCache = ‪$pageTitleCache;
81  }
82 
87  private function ‪getPageTitleProviderConfiguration(): array
88  {
89  $typoscriptService = GeneralUtility::makeInstance(TypoScriptService::class);
90  $config = $typoscriptService->convertTypoScriptArrayToPlainArray(
91  ‪$GLOBALS['TSFE']->config['config'] ?? []
92  );
93 
94  return $config['pageTitleProviders'] ?? [];
95  }
96 
102  protected function ‪setProviderOrder(array $orderInformation): array
103  {
104  foreach ($orderInformation as $provider => &$configuration) {
105  if (isset($configuration['before'])) {
106  if (is_string($configuration['before'])) {
107  $configuration['before'] = GeneralUtility::trimExplode(',', $configuration['before'], true);
108  } elseif (!is_array($configuration['before'])) {
109  throw new \UnexpectedValueException(
110  'The specified "before" order configuration for provider "' . $provider . '" is invalid.',
111  1535803185
112  );
113  }
114  }
115  if (isset($configuration['after'])) {
116  if (is_string($configuration['after'])) {
117  $configuration['after'] = GeneralUtility::trimExplode(',', $configuration['after'], true);
118  } elseif (!is_array($configuration['after'])) {
119  throw new \UnexpectedValueException(
120  'The specified "after" order configuration for provider "' . $provider . '" is invalid.',
121  1535803186
122  );
123  }
124  }
125  }
126  return $orderInformation;
127  }
128 }
‪TYPO3\CMS\Core\PageTitle\PageTitleProviderManager\setProviderOrder
‪string[] setProviderOrder(array $orderInformation)
Definition: PageTitleProviderManager.php:101
‪TYPO3\CMS\Core\PageTitle
Definition: AbstractPageTitleProvider.php:4
‪TYPO3\CMS\Core\PageTitle\PageTitleProviderManager\setPageTitleCache
‪setPageTitleCache(array $pageTitleCache)
Definition: PageTitleProviderManager.php:77
‪TYPO3\CMS\Core\PageTitle\PageTitleProviderManager\getPageTitleProviderConfiguration
‪array getPageTitleProviderConfiguration()
Definition: PageTitleProviderManager.php:86
‪TYPO3\CMS\Core\PageTitle\PageTitleProviderManager
Definition: PageTitleProviderManager.php:28
‪TYPO3\CMS\Core\Service\DependencyOrderingService
Definition: DependencyOrderingService.php:31
‪TYPO3\CMS\Core\PageTitle\PageTitleProviderManager\getTitle
‪string getTitle()
Definition: PageTitleProviderManager.php:38
‪TYPO3\CMS\Core\TypoScript\TypoScriptService
Definition: TypoScriptService.php:23
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\PageTitle\PageTitleProviderManager\$pageTitleCache
‪array $pageTitleCache
Definition: PageTitleProviderManager.php:31
‪TYPO3\CMS\Core\PageTitle\PageTitleProviderManager\getPageTitleCache
‪array getPageTitleCache()
Definition: PageTitleProviderManager.php:68
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45