From 1651f2a5e12008ec7c0efcd6daa2ef3942cd188d Mon Sep 17 00:00:00 2001 From: Benni Mack <benni@typo3.org> Date: Tue, 5 Jul 2022 13:05:25 +0200 Subject: [PATCH] [TASK] Move Page Title Generation for search out of TSFE This change removes the internal property "indexedDocTitle" which is filled by the PageTitleProvider API. This API is then moved to Indexed Search to use the same logic to fetch the "real" page title (without site title etc) when a plugin is registered. Resolves: #97861 Releases: main Change-Id: Ide1b8d1b700d9e555e02d4a02af154f05cb54130 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/75036 Tested-by: core-ci <typo3@b13.com> Tested-by: Oliver Bartsch <bo@cedev.de> Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de> Reviewed-by: Oliver Bartsch <bo@cedev.de> Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de> --- .../TypoScriptFrontendController.php | 22 -------------- .../TypoScriptFrontendControllerTest.php | 29 ------------------- .../Classes/Hook/TypoScriptFrontendHook.php | 9 ++++-- 3 files changed, 7 insertions(+), 53 deletions(-) diff --git a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php index 40c7d85cc6e2..f6b3da6900f9 100644 --- a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php +++ b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php @@ -356,13 +356,6 @@ class TypoScriptFrontendController implements LoggerAwareInterface */ protected string $uniqueString = ''; - /** - * This value will be used as the title for the page in the indexer (if - * indexing happens) - * @internal only used by TYPO3 Core, use PageTitle API instead. - */ - public string $indexedDocTitle = ''; - /** * The base URL set for the page header. * @var string @@ -1183,11 +1176,6 @@ class TypoScriptFrontendController implements LoggerAwareInterface // Restore the current tags as they can be retrieved by getPageCacheTags() $this->pageCacheTags = $cachedData['cacheTags'] ?? []; - // Restore page title information, this is needed to generate the page title for - // partially cached pages. - $this->page['title'] = $cachedData['pageTitleInfo']['title']; - $this->indexedDocTitle = $cachedData['pageTitleInfo']['indexedDocTitle']; - if (isset($this->config['config']['debug'])) { $debugCacheTime = (bool)$this->config['config']['debug']; } else { @@ -1666,10 +1654,6 @@ class TypoScriptFrontendController implements LoggerAwareInterface 'cache_data' => $data, 'expires' => $expirationTstamp, 'tstamp' => $GLOBALS['EXEC_TIME'], - 'pageTitleInfo' => [ - 'title' => $this->page['title'], - 'indexedDocTitle' => $this->indexedDocTitle, - ], ]; $this->cacheExpires = $expirationTstamp; $this->pageCacheTags[] = 'pageId_' . $cacheData['page_id']; @@ -1820,8 +1804,6 @@ class TypoScriptFrontendController implements LoggerAwareInterface public function preparePageContentGeneration(ServerRequestInterface $request) { $this->getTimeTracker()->push('Prepare page content generation'); - // Global vars... - $this->indexedDocTitle = $this->page['title'] ?? null; // Base url: if (isset($this->config['config']['baseURL'])) { $this->baseUrl = $this->config['config']['baseURL']; @@ -1929,10 +1911,6 @@ class TypoScriptFrontendController implements LoggerAwareInterface $pageTitle = $titleProvider->getTitle(); $this->config['config']['pageTitleCache'] = $titleProvider->getPageTitleCache(); - if ($pageTitle !== '') { - $this->indexedDocTitle = $pageTitle; - } - $titleTagContent = $this->printTitle( $pageTitle, (bool)($this->config['config']['noPageTitle'] ?? false), diff --git a/typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php b/typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php index 9e9ceb42c164..f4d35dcf2da8 100644 --- a/typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php +++ b/typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php @@ -40,7 +40,6 @@ use TYPO3\CMS\Core\Package\PackageManager; use TYPO3\CMS\Core\Page\ImportMap; use TYPO3\CMS\Core\Page\ImportMapFactory; use TYPO3\CMS\Core\Page\PageRenderer; -use TYPO3\CMS\Core\PageTitle\PageTitleProviderManager; use TYPO3\CMS\Core\Routing\PageArguments; use TYPO3\CMS\Core\Site\Entity\Site; use TYPO3\CMS\Core\Site\Entity\SiteLanguage; @@ -278,34 +277,6 @@ class TypoScriptFrontendControllerTest extends UnitTestCase self::assertSame($expected, $this->subject->baseUrlWrap($url)); } - /** - * @test - * @see https://forge.typo3.org/issues/88041 - */ - public function indexedSearchHookUsesPageTitleApi(): void - { - $pageTitle = 'This is a test page title coming from PageTitleProviderManager'; - - $pageTitleProvider = $this->prophesize(PageTitleProviderManager::class); - $pageTitleProvider->getTitle()->willReturn($pageTitle); - $pageTitleProvider->getPageTitleCache()->willReturn([]); - GeneralUtility::setSingletonInstance(PageTitleProviderManager::class, $pageTitleProvider->reveal()); - - $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class); - $cacheFrontendProphecy->get(Argument::cetera())->willReturn(false); - $cacheFrontendProphecy->set(Argument::cetera())->willReturn(null); - $cacheManagerProphecy = $this->prophesize(CacheManager::class); - $cacheManagerProphecy->getCache('pages')->willReturn($cacheFrontendProphecy->reveal()); - GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal()); - - $contentObjectRendererProphecy = $this->prophesize(ContentObjectRenderer::class); - $contentObjectRendererProphecy->stdWrapValue(Argument::cetera())->willReturn(''); - $this->subject->cObj = $contentObjectRendererProphecy->reveal(); - - $this->subject->generatePageTitle(); - self::assertSame($pageTitle, $this->subject->indexedDocTitle); - } - /** * @test */ diff --git a/typo3/sysext/indexed_search/Classes/Hook/TypoScriptFrontendHook.php b/typo3/sysext/indexed_search/Classes/Hook/TypoScriptFrontendHook.php index f0c0c3998759..838e647d8d56 100644 --- a/typo3/sysext/indexed_search/Classes/Hook/TypoScriptFrontendHook.php +++ b/typo3/sysext/indexed_search/Classes/Hook/TypoScriptFrontendHook.php @@ -18,6 +18,7 @@ namespace TYPO3\CMS\IndexedSearch\Hook; use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Context\LanguageAspect; +use TYPO3\CMS\Core\PageTitle\PageTitleProviderManager; use TYPO3\CMS\Core\TimeTracker\TimeTracker; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; @@ -107,10 +108,14 @@ class TypoScriptFrontendHook // Content of page $configuration['content'] = $tsfe->content; // Content string (HTML of TYPO3 page) - $configuration['indexedDocTitle'] = $tsfe->indexedDocTitle; + // Alternative title for indexing - $configuration['mtime'] = $tsfe->register['SYS_LASTCHANGED'] ?? $tsfe->page['SYS_LASTCHANGED']; + // @see https://forge.typo3.org/issues/88041 + $titleProvider = GeneralUtility::makeInstance(PageTitleProviderManager::class); + $configuration['indexedDocTitle'] = $titleProvider->getTitle(); + // Most recent modification time (seconds) of the content on the page. Used to evaluate whether it should be re-indexed. + $configuration['mtime'] = $tsfe->register['SYS_LASTCHANGED'] ?? $tsfe->page['SYS_LASTCHANGED']; // Configuration of behavior $configuration['index_externals'] = $tsfe->config['config']['index_externals']; // Whether to index external documents like PDF, DOC etc. (if possible) -- GitLab