..  include:: /Includes.rst.txt

..  _feature-108462-1765368045:

========================================================================
Feature: #108462 - Add PSR-14 Event AfterPageContentPreviewRenderedEvent
========================================================================

See :issue:`108462`

Description
===========

The class :php:`\TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem` is
the central entity to generate various previews of content elements.

Developers can either use the event :php:`\TYPO3\CMS\Backend\View\Event\PageContentPreviewRenderingEvent`
to generate a preview or implementing :php:`\TYPO3\CMS\Backend\Preview\PreviewRendererInterface`.

The new PSR-14 event :php:`\TYPO3\CMS\Backend\View\Event\AfterPageContentPreviewRenderedEvent`
can now be used to enrich the output generated by one of those.

Example
=======

An example event listener could look like this:

..  code-block:: php
    :caption: Example event listener class

    namespace MyVendor\MyExtension\EventListener;

    use TYPO3\CMS\Backend\View\Event\AfterPageContentPreviewRenderedEvent;
    use TYPO3\CMS\Core\Attribute\AsEventListener;

    #[AsEventListener('my-extension')]
    final class AfterPageContentPreviewRenderedEventListener
    {
        public function __invoke(AfterPageContentPreviewRenderedEvent $event): void
        {
            $content = 'before<hr />'. $event->getPreviewContent() . '<hr />after';
            $event->setPreviewContent($content);
        }
    }


Impact
======

As integrator it is sometimes handy to enrich the previews of other
content elements and plugins to display additional fields.


..  index:: Backend, PHP-API, ext:backend
