‪TYPO3CMS  10.4
PageTitleProviderManager.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\Log\LoggerAwareInterface;
21 use Psr\Log\LoggerAwareTrait;
26 
30 class ‪PageTitleProviderManager implements ‪SingletonInterface, LoggerAwareInterface
31 {
32  use LoggerAwareTrait;
33 
37  private ‪$pageTitleCache = [];
38 
42  public function ‪getTitle(): string
43  {
44  $pageTitle = '';
45 
46  $titleProviders = $this->‪getPageTitleProviderConfiguration();
47  $titleProviders = $this->‪setProviderOrder($titleProviders);
48 
49  $orderedTitleProviders = GeneralUtility::makeInstance(DependencyOrderingService::class)
50  ->orderByDependencies($titleProviders);
51 
52  $this->logger->debug(
53  'Page title providers ordered',
54  ['orderedTitleProviders' => $orderedTitleProviders]
55  );
56 
57  foreach ($orderedTitleProviders as $provider => $configuration) {
58  if (class_exists($configuration['provider']) && is_subclass_of($configuration['provider'], PageTitleProviderInterface::class)) {
60  $titleProviderObject = GeneralUtility::makeInstance($configuration['provider']);
61  if (($pageTitle = $titleProviderObject->getTitle())
62  || ($pageTitle = $this->pageTitleCache[$configuration['provider']] ?? '') !== ''
63  ) {
64  $this->logger->debug(
65  'Page title provider ' . $configuration['provider'] . ' used',
66  ['title' => $pageTitle, 'providerUsed' => $configuration['provider']]
67  );
68  $this->pageTitleCache[$configuration['provider']] = $pageTitle;
69  break;
70  }
71  $this->logger->debug(
72  'Page title provider ' . $configuration['provider'] . ' skipped',
73  ['name' => $provider, 'skippedProvider' => $configuration['provider']]
74  );
75  }
76  }
77 
78  return $pageTitle;
79  }
80 
85  public function ‪getPageTitleCache(): array
86  {
88  }
89 
94  public function ‪setPageTitleCache(array ‪$pageTitleCache): void
95  {
96  $this->pageTitleCache = ‪$pageTitleCache;
97  }
98 
103  private function ‪getPageTitleProviderConfiguration(): array
104  {
105  $typoscriptService = GeneralUtility::makeInstance(TypoScriptService::class);
106  $config = $typoscriptService->convertTypoScriptArrayToPlainArray(
107  ‪$GLOBALS['TSFE']->config['config'] ?? []
108  );
109 
110  return $config['pageTitleProviders'] ?? [];
111  }
112 
118  protected function ‪setProviderOrder(array $orderInformation): array
119  {
120  foreach ($orderInformation as $provider => &$configuration) {
121  if (isset($configuration['before'])) {
122  if (is_string($configuration['before'])) {
123  $configuration['before'] = ‪GeneralUtility::trimExplode(',', $configuration['before'], true);
124  } elseif (!is_array($configuration['before'])) {
125  throw new \UnexpectedValueException(
126  'The specified "before" order configuration for provider "' . $provider . '" is invalid.',
127  1535803185
128  );
129  }
130  }
131  if (isset($configuration['after'])) {
132  if (is_string($configuration['after'])) {
133  $configuration['after'] = ‪GeneralUtility::trimExplode(',', $configuration['after'], true);
134  } elseif (!is_array($configuration['after'])) {
135  throw new \UnexpectedValueException(
136  'The specified "after" order configuration for provider "' . $provider . '" is invalid.',
137  1535803186
138  );
139  }
140  }
141  }
142  return $orderInformation;
143  }
144 }
‪TYPO3\CMS\Core\PageTitle\PageTitleProviderManager\setProviderOrder
‪string[] setProviderOrder(array $orderInformation)
Definition: PageTitleProviderManager.php:117
‪TYPO3\CMS\Core\PageTitle
Definition: AbstractPageTitleProvider.php:18
‪TYPO3\CMS\Core\PageTitle\PageTitleProviderManager\setPageTitleCache
‪setPageTitleCache(array $pageTitleCache)
Definition: PageTitleProviderManager.php:93
‪TYPO3\CMS\Core\PageTitle\PageTitleProviderManager\getPageTitleProviderConfiguration
‪array getPageTitleProviderConfiguration()
Definition: PageTitleProviderManager.php:102
‪TYPO3\CMS\Core\PageTitle\PageTitleProviderManager
Definition: PageTitleProviderManager.php:31
‪TYPO3\CMS\Core\Service\DependencyOrderingService
Definition: DependencyOrderingService.php:32
‪TYPO3\CMS\Core\PageTitle\PageTitleProviderManager\getTitle
‪string getTitle()
Definition: PageTitleProviderManager.php:41
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪TYPO3\CMS\Core\TypoScript\TypoScriptService
Definition: TypoScriptService.php:25
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\PageTitle\PageTitleProviderManager\$pageTitleCache
‪array $pageTitleCache
Definition: PageTitleProviderManager.php:36
‪TYPO3\CMS\Core\PageTitle\PageTitleProviderManager\getPageTitleCache
‪array getPageTitleCache()
Definition: PageTitleProviderManager.php:84
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46