Deprecation: #110348 - AssetCollector media handling
See forge#110348
Description
The media related methods of
\TYPO3\ have
been marked as deprecated and will be removed in TYPO3 v16.0:
AssetCollector->add Media () AssetCollector->get Media () AssetCollector->has Media () AssetCollector->remove Media ()
Unlike JavaScript and stylesheet assets, collected media never contributed
anything to the rendered output. The registry is a leftover of the
$TSFE->images property, which was moved to the
Asset in TYPO3 v10.3 (see Deprecation: #90522 - TSFE properties regarding images) and only
ever served the "Images on this page" section of the admin panel.
Collecting this information by having every image renderer report into a
central registry is fragile: it only ever covered the code paths that
remembered to call
add. TYPO3 dispatches
\TYPO3\ for every
processed file, which is a complete and more precise source for the same
information.
Impact
Calling one of the deprecated methods triggers a PHP
E_
error.
TYPO3 Core does not populate the registry anymore. The two places that used
to do so no longer call
add:
\TYPO3\CMS\ Extbase\ Service\ Image Service->apply Processing Instructions () \TYPO3\(theCMS\ Frontend\ Content Object\ Image Content Object IMAGEcontent object)
Consequently
Asset only returns entries that were
added by third-party code.
The admin panel keeps its "Images on this page" section. It now collects the
data through a PSR-14 listener on
After, which also
reports correct file sizes for images stored in remote storages and adds the
image dimensions.
Affected installations
Installations with extensions calling any of the deprecated methods, and
installations relying on Core populating the registry. Custom image
ViewHelpers or content objects that mirrored the Core behaviour by calling
add are the most likely candidates.
The methods are not covered by the extension scanner: their names are too generic to be matched reliably.
Migration
Remove calls to
add and
remove — they serve no
rendering purpose.
To collect the images processed during a request, register a PSR-14 event listener instead. This works regardless of whether an image is rendered through Fluid, TypoScript or custom code:
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Resource\Event\AfterFileProcessingEvent;
use TYPO3\CMS\Core\SingletonInterface;
final class MyImageCollector implements SingletonInterface
{
private array $images = [];
#[AsEventListener('my-extension/collect-images')]
public function collect(AfterFileProcessingEvent $event): void
{
$processedFile = $event->getProcessedFile();
$publicUrl = $processedFile->getPublicUrl();
if ($publicUrl !== null) {
$this->images[$publicUrl] = $processedFile;
}
}
public function getImages(): array
{
return $this->images;
}
}
Note that the event fires for every processed file of a request, including files that are processed but never emitted into the output.