Skip to content

Commit 4a8e945

Browse files
brotkruemlgithub-actions[bot]
authored andcommitted
[TASK] Use request attribute instead of TSFE in page title API example
The TypoScriptFrontendController has been marked as deprecated with TYPO3 v13.4. Therefore, this example has been adjusted to avoid calling TSFE methods. Additionally: - The whole class is marked as readonly. - The "do something" comment is removed as it does not serve any purpose here. Related: TYPO3-Documentation/Changelog-To-Doc#1074 Releases: main, 13.4
1 parent 3b4a2be commit 4a8e945

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

Documentation/ApiOverview/Seo/PageTitleApi.rst

+4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ example the site title, you can implement a page title provider as follows:
8080
.. literalinclude:: _ExampleWebsiteTitle/_WebsiteTitleProvider.php
8181
:caption: EXT:my_sitepackage/Classes/PageTitle/WebsiteTitleProvider.php
8282

83+
.. versionchanged:: 13.0
84+
The :ref:`frontend.page.information attribute <typo3-request-attribute-frontend-page-information>`
85+
has been introduced.
86+
8387
As we need to :ref:`inject <DependencyInjection>` the class :php:`SiteFinder`
8488
to retrieve the current site configuration, we must make the new page title
8589
provider :ref:`public <knowing-what-to-make-public>`:

Documentation/ApiOverview/Seo/_ExampleWebsiteTitle/_WebsiteTitleProvider.php

+11-8
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,33 @@
44

55
namespace MyVendor\MySitepackage\PageTitle;
66

7+
use Psr\Http\Message\ServerRequestInterface;
78
use TYPO3\CMS\Core\PageTitle\PageTitleProviderInterface;
89
use TYPO3\CMS\Core\Site\SiteFinder;
9-
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
10+
use TYPO3\CMS\Frontend\Page\PageInformation;
1011

11-
final class WebsiteTitleProvider implements PageTitleProviderInterface
12+
final readonly class WebsiteTitleProvider implements PageTitleProviderInterface
1213
{
1314
public function __construct(
14-
private readonly SiteFinder $siteFinder,
15+
private SiteFinder $siteFinder,
1516
) {}
1617

1718
public function getTitle(): string
1819
{
19-
$site = $this->siteFinder->getSiteByPageId($this->getTypoScriptFrontendController()->page['uid']);
20+
/** @var PageInformation $pageInformation */
21+
$pageInformation = $this->getRequest()->getAttribute('frontend.page.information');
22+
23+
$site = $this->siteFinder->getSiteByPageId($pageInformation->getId());
2024
$titles = [
21-
$this->getTypoScriptFrontendController()->page['title'],
25+
$pageInformation->getPageRecord()['title'],
2226
$site->getAttribute('websiteTitle'),
2327
];
2428

25-
// do something
2629
return implode(' - ', $titles);
2730
}
2831

29-
private function getTypoScriptFrontendController(): TypoScriptFrontendController
32+
private function getRequest(): ServerRequestInterface
3033
{
31-
return $GLOBALS['TSFE'];
34+
return $GLOBALS['TYPO3_REQUEST'];
3235
}
3336
}

0 commit comments

Comments
 (0)