Feature: #110277 - Register file renderers as tagged services 

See forge#110277

Description 

File renderers, used for example by the <f:media> ViewHelper to render audio, video or online media files, are now registered as tagged services via dependency injection instead of the previous programmatic registration through \TYPO3\CMS\Core\Resource\Rendering\RendererRegistry->registerRendererClass() in ext_localconf.php.

A file renderer class implementing \TYPO3\CMS\Core\Resource\Rendering\FileRendererInterface is registered by adding the new PHP attribute \TYPO3\CMS\Core\Attribute\AsFileRenderer to the class:

EXT:my_extension/Classes/Resource/Rendering/MyVideoRenderer.php
use TYPO3\CMS\Core\Attribute\AsFileRenderer;
use TYPO3\CMS\Core\Resource\Rendering\FileRendererInterface;

#[AsFileRenderer(priority: 10)]
final class MyVideoRenderer implements FileRendererInterface
{
    // ...
}
Copied!

The renderer priority is defined at registration time via the attribute. Renderers with a higher priority are asked first whether they can render a given file ( canRender() ). The file renderers shipped with TYPO3 Core are registered with the default priority 0 (previously 1 via the removed getPriority() method), so any custom renderer using a priority above 0 takes precedence over them. The order in which renderers of the same priority are evaluated is not defined and must not be relied upon; use distinct priorities if the evaluation order matters.

Alternatively, the service tag fal.file_renderer can be used directly in Configuration/Services.yaml:

EXT:my_extension/Configuration/Services.yaml
MyVendor\MyExtension\Resource\Rendering\MyVideoRenderer:
  tags:
    - name: fal.file_renderer
      priority: 10
Copied!

Impact 

Registering file renderers as tagged services has the following benefits over the previous programmatic registration:

  • The registration is resolved once at container compile time instead of executing registration code from ext_localconf.php on every request. Loading and validating the renderer classes per request, as well as instantiating and sorting them by priority at runtime, is not necessary anymore.
  • File renderers are proper services now and can use dependency injection in their constructor.
  • The renderer priority is declared at the class itself instead of depending on the loading order of ext_localconf.php files.
  • The registration is validated at container compile time: a service tagged as fal.file_renderer that does not implement FileRendererInterface fails the container build with a speaking exception, instead of causing errors when a file is rendered.

Registration in ext_localconf.php via RendererRegistry->registerRendererClass() is not evaluated anymore, see Breaking: #110277 - File renderer registration and interface changed for the upgrade path.