AfterImageResourceResolvedEvent

New in version 13.0: This event serves as a drop-in replacement for the removed hook $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getImgResource'].

The PSR-14 event \TYPO3\CMS\Frontend\ContentObject\Event\AfterImageResourceResolvedEvent is being dispatched just before ContentObjectRenderer->getImgResource() is about to return the resolved \TYPO3\CMS\Core\Imaging\ImageResource DTO. Therefore, the event is - in comparison to the removed hook - always dispatched, even if no ImageResource could be resolved. In this case, the corresponding return value is null.

Example

EXT:my_extension/Classes/Frontend/EventListener/MyEventListener.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Frontend\EventListener;

use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Frontend\ContentObject\Event\AfterImageResourceResolvedEvent;

#[AsEventListener(
    identifier: 'my-extension/my-event-listener'
)]
final class MyEventListener
{
    public function __invoke(AfterImageResourceResolvedEvent $event): void
    {
        $modifiedImageResource = $event
            ->getImageResource()
            ->withWidth(123);

        $event->setImageResource($modifiedImageResource);
    }
}

New in version 13.0: The PHP attribute \TYPO3\CMS\Core\Attribute\AsEventListener has been introduced to tag a PHP class as an event listener. Alternatively, you can also register an event listener via the Configuration/Services.yaml file. Have a look into the section Implementing an event listener in your extension.

API

class TYPO3\CMS\Frontend\ContentObject\Event\AfterImageResourceResolvedEvent

Listeners are able to modify the resolved ContentObjectRenderer->getImgResource() result

getFile()
Return type

TYPO3\CMS\Core\Resource\File|TYPO3\CMS\Core\Resource\FileReference|string

getFileArray()
Return type

array

getImageResource()
Return type

TYPO3\CMS\Core\Imaging\ImageResource

setImageResource(TYPO3\\CMS\\Core\\Imaging\\ImageResource $imageResource)
Parameters
  • $imageResource (TYPO3\CMS\Core\Imaging\ImageResource) -- the imageResource