Feature: #101388 - Set the canonical URL from uncached plugins 

See forge#101388

Description 

The canonical URL generated by EXT:seo is now managed by the Meta Tag API. A new meta tag manager handles the property canonical and renders it as <link rel="canonical" href="…"> .

The canonical URL is still determined while the cacheable part of the page is generated, and the PSR-14 event \TYPO3\CMS\Seo\Event\ModifyUrlForCanonicalTagEvent is still dispatched. The resulting URL is stored together with the other meta tags in the page cache and rendered after uncached content objects ( USER_INT , COA_INT , uncached Extbase actions) have been processed.

Uncached plugins can therefore replace the canonical URL:

EXT:my_extension/Classes/Controller/ProductController.php
use TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry;

public function __construct(
    private readonly MetaTagManagerRegistry $metaTagManagerRegistry,
) {}

public function filterAction(): ResponseInterface
{
    $this->metaTagManagerRegistry
        ->getManagerForProperty('canonical')
        ->addProperty('canonical', 'https://example.com/products/');
    // ...
}
Copied!

A page has a single canonical URL, so adding the property always replaces the previous value. Removing the property suppresses the tag:

$this->metaTagManagerRegistry
    ->getManagerForProperty('canonical')
    ->removeProperty('canonical');
Copied!

Impact 

The canonical URL can be set, replaced and removed from cached and uncached plugins through the Meta Tag API, consistently on the first request and when the page is served from the page cache.

The <link rel="canonical"> tag is now rendered together with the meta tags instead of the additional header data, which changes its position within the <head> section.