Feature: #110277 - Register file renderers as tagged services
See forge#110277
Description
File renderers, used for example by the
<f: 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\
in ext_localconf.php.
A file renderer class implementing
\TYPO3\ is
registered by adding the new PHP attribute
\TYPO3\ to the class:
use TYPO3\CMS\Core\Attribute\AsFileRenderer;
use TYPO3\CMS\Core\Resource\Rendering\FileRendererInterface;
#[AsFileRenderer(priority: 10)]
final class MyVideoRenderer implements FileRendererInterface
{
// ...
}
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 (
can). The file renderers shipped with TYPO3
Core are registered with the default priority
0
(previously
1
via the removed
get 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. can be used
directly in Configuration/Services.yaml:
MyVendor\MyExtension\Resource\Rendering\MyVideoRenderer:
tags:
- name: fal.file_renderer
priority: 10
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.phpon 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.phpfiles. - The registration is validated at container compile time: a service
tagged as
fal.that does not implementfile_ renderer Filefails the container build with a speaking exception, instead of causing errors when a file is rendered.Renderer Interface
Registration in ext_localconf.php via
Renderer is not evaluated
anymore, see Breaking: #110277 - File renderer registration and interface changed for the upgrade path.