Feature: #110287 - Register meta tag managers as tagged services
See forge#110287
Description
Meta tag managers, used to manage and render the
<meta>
tags of a
page, are now registered as tagged services via dependency injection
instead of the previous programmatic registration through
\TYPO3\
in ext_localconf.php.
A meta tag manager class implementing
\TYPO3\ (usually by
extending
\TYPO3\) is
registered by adding the new PHP attribute
\TYPO3\ to the class:
use TYPO3\CMS\Core\Attribute\AsMetaTagManager;
use TYPO3\CMS\Core\MetaTag\AbstractMetaTagManager;
#[AsMetaTagManager(identifier: 'my-manager')]
final class MyMetaTagManager extends AbstractMetaTagManager
{
// ...
}
The manager order is defined at registration time via the optional
before
and
after
attribute arguments, referencing the
identifiers of other managers. A manager without constraints is ordered
before the
generic
manager shipped with TYPO3 Core, which handles
every property and therefore always comes last — this matches the
previous default of
register.
#[AsMetaTagManager(identifier: 'my-manager', before: ['opengraph'], after: ['html5'])]
Alternatively, the service tag
metatag. can be used
directly in Configuration/Services.yaml, with before and
after given as comma-separated lists:
MyVendor\MyExtension\MetaTag\MyMetaTagManager:
tags:
- name: metatag.manager
identifier: 'my-manager'
Impact
Registering meta tag managers as tagged services has the following benefits over the previous programmatic registration:
- The registration and the resolution of the
before/afterordering constraints happen once at container compile time instead of executing registration code fromext_localconf.phpand sorting the managers on every request. - Meta tag managers are proper services now and can use dependency injection in their constructor.
- The registration is validated at container compile time: a service
tagged as
metatag.that does not implementmanager Meta, or is missing theTag Manager Interface identifiertag attribute, fails the container build with a speaking exception.
Registration in ext_localconf.php via
Meta is not evaluated
anymore, see Breaking: #110287 - Meta tag manager registration and interface changed for the upgrade path.