Skip to content

Commit

Permalink
[Backport 13.4] [!!!][TASK] Activate setRequest() in PageTitleProvide…
Browse files Browse the repository at this point in the history
…rInterface (#4976)

* [!!!][TASK] Activate setRequest() in PageTitleProviderInterface

While not yet mandatory this example
also works in TYPO3 13.4, therefore we backport

releases: main, 13.4
references: TYPO3-Documentation/Changelog-To-Doc#1133

* Apply suggestions from code review

Co-authored-by: Chris Müller <[email protected]>

* Fix tests

---------

Co-authored-by: lina.wolf <[email protected]>
Co-authored-by: Lina Wolf <[email protected]>
Co-authored-by: Chris Müller <[email protected]>
  • Loading branch information
4 people authored Nov 1, 2024
1 parent 2599b9e commit 8a4eac5
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,34 @@
#[Autoconfigure(public: true)]
final readonly class WebsiteTitleProvider implements PageTitleProviderInterface
{
private ServerRequestInterface $request;

public function __construct(
private SiteFinder $siteFinder,
) {}

public function getTitle(): string
{
/** @var PageInformation $pageInformation */
$pageInformation = $this->getRequest()->getAttribute('frontend.page.information');

$site = $this->siteFinder->getSiteByPageId($pageInformation->getId());
$site = $this->siteFinder->getSiteByPageId($this->getPageInformation()->getId());
$titles = [
$pageInformation->getPageRecord()['title'],
$this->getPageInformation()->getPageRecord()['title'] ?? '',
$site->getAttribute('websiteTitle'),
];

return implode(' - ', $titles);
}

private function getRequest(): ServerRequestInterface
public function setRequest(ServerRequestInterface $request): void
{
$this->request = $request;
}

private function getPageInformation(): PageInformation
{
return $GLOBALS['TYPO3_REQUEST'];
$pageInformation = $this->request->getAttribute('frontend.page.information');
if (!$pageInformation instanceof PageInformation) {
throw new \Exception('Current frontend page information not available', 1730098625);
}
return $pageInformation;
}
}

0 comments on commit 8a4eac5

Please sign in to comment.