Feature: #102624 - PSR-14 event for modifying image source collection

See forge#102624

Description

A new PSR-14 event \TYPO3\CMS\Frontend\ContentObject\Event\ModifyImageSourceCollectionEvent has been introduced which serves as a drop-in replacement for the now removed hook $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getImageSourceCollection'].

The event is being dispatched in ContentObjectRenderer->getImageSourceCollection() for each configured sourceCollection and allows to enrich the final source collection result.

To modify getImageSourceCollection() result, the following methods are available:

  • setSourceCollection(): Allows to modify a source collection based on the corresponding configuration

  • getSourceCollection(): Returns the source collection

  • getFullSourceCollection(): Returns the current full source collection, being enhanced by the current sourceCollection

  • getSourceConfiguration(): Returns the current sourceCollection configuration

  • getSourceRenderConfiguration(): Returns the corresponding renderer configuration for the source collection

  • getContentObjectRenderer(): Returns the current ContentObjectRenderer instance

Example

The event listener class, using the PHP attribute #[AsEventListener] for registration:

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

final class ModifyImageSourceCollectionEventListener
{
    #[AsEventListener]
    public function __invoke(ModifyImageSourceCollectionEvent $event): void
    {
        $event->setSourceCollection('<source src="bar-file.jpg" media="(max-device-width: 600px)">');
    }
}

Impact

Using the new PSR-14 event, it's now possible to manipulate the sourceCollection's, used for an ImageContentObject.