Breaking: #110277 - File renderer registration and interface changed
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 (see
Feature: #110277 - Register file renderers as tagged services). This comes with the following breaking
changes:
\TYPO3\is now a no-op. Calling the method has no effect anymore, but triggers anCMS\ Core\ Resource\ Rendering\ Renderer Registry->register Renderer Class () E_notice. The method will be removed in TYPO3 v16.0.USER_ DEPRECATED \TYPO3\does not extendCMS\ Core\ Resource\ Rendering\ File Renderer Interface \TYPO3\anymore. File renderers are shared services managed by the dependency injection container.CMS\ Core\ Singleton Interface - The method
gethas been removed fromPriority () File. The renderer priority is now defined at registration time via theRenderer Interface #attribute or the[As File Renderer] fal.service tag. Note that the file renderers shipped with TYPO3 Core previously returned a priority offile_ renderer 1fromgetand are now registered with the attribute's default priority ofPriority () 0. Custom renderers that relied on a priority of0to rank strictly below all Core renderers now rank equally with them instead and should use a negative priority to keep the previous ordering. - Renderers registered with the same priority are no longer guaranteed
to be asked in the order they were added: previously, same-priority
renderers kept the order in which
Rendererwas called fromRegistry->register Renderer Class () ext_. The order of same-priority tagged services is now an implementation detail of the dependency injection container and must not be relied upon. Extensions that depend on a specific evaluation order between renderers should assign distinct priorities instead.localconf. php - The remaining methods of
Fileare now strictly typed:Renderer Interface canandRender (File Interface $file): bool render.(File Interface $file, int |string $width, int |string $height, array $options = []): string - The methods
createandRenderer Instance () comparehave been removed fromRenderer Priority () Renderer, the methodRegistry gethas been changed from public to protected visibility, and the remaining methods are now strictly typed.Renderer Instances () Rendereris now marked asRegistry @internal, since registering file renderers does not require interacting with the registry anymore. TYPO3 Core resolves the matching renderer viagetinternally, for example in theRenderer () <f:ViewHelper.media>
Impact
File renderers registered via
Renderer in
ext_ are no longer evaluated. The corresponding
files (audio, video or online media) are no longer rendered by the custom
renderer until it is registered as a tagged service.
Custom renderer classes implementing
File without
the adapted method signatures will cause a fatal PHP error.
Affected installations
All installations with custom extensions registering file renderers via
Renderer, or providing custom
implementations of
File. The extension scanner
reports usages of
register as weak match.
Migration
Remove the
Renderer call from
ext_ and add the
# attribute
to the renderer class instead. Move the priority previously returned by
get to the attribute and remove the method. Add the
native type declarations to
can and
render:
use TYPO3\CMS\Core\Attribute\AsFileRenderer;
use TYPO3\CMS\Core\Resource\FileInterface;
use TYPO3\CMS\Core\Resource\Rendering\FileRendererInterface;
#[AsFileRenderer(priority: 10)]
final class MyVideoRenderer implements FileRendererInterface
{
public function canRender(FileInterface $file): bool
{
// ...
}
public function render(FileInterface $file, int|string $width, int|string $height, array $options = []): string
{
// ...
}
}
In case the extension supports both TYPO3 v14 and v15, keep the
get method (it is simply unused in v15) and register the
renderer in both ways: the ext_ registration is
evaluated in v14, the attribute in v15. Since PHP parameter types must
not be narrowed in implementations, keep the
$width
and
$height
parameters untyped in this case — only the
bool
and
string
return type declarations are compatible with both
versions.
Code that called
Renderer to
inspect all registered renderers should inject
Renderer
and use
get to retrieve the matching renderer for
a given file instead.