Files
VITEC-website/packages/vitec/Classes/Seo/VitecMetaHandler.php
2026-08-28 13:57:54 +02:00

36 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Evomedien\Vitec\Seo;
use FriendsOfTYPO3\Headless\Seo\MetaHandler;
use Psr\Http\Message\ServerRequestInterface;
/**
* Mirrors the real page <title> into `meta.title` of the page JSON.
*
* Why: `meta.title` is rendered from TypoScript (lib.meta) BEFORE the page
* content, so on product/usecase detail pages it still shows the generic
* page title ("Product") - the record's seotitle only reaches the
* PageTitleProvider while the content renders. Headless fixes `seo.title`
* afterwards through this handler; we extend it so `meta.title` gets the
* same final value. Registered via the MetaHandlerInterface alias in
* Services.yaml, which covers both the cacheable listener and the
* USER_INT middleware path.
*/
class VitecMetaHandler extends MetaHandler
{
public function process(ServerRequestInterface $request, array $content): array
{
$content = parent::process($request, $content);
$title = trim((string)($content['seo']['title'] ?? ''));
if ($title !== '' && is_array($content['meta'] ?? null)) {
$content['meta']['title'] = $title;
}
return $content;
}
}