IsContentUsedOnPageLayoutEvent

Use the PSR-14 event \TYPO3\CMS\Backend\View\Event\IsContentUsedOnPageLayoutEvent to identify if content has been used in a column that is not in a backend layout.

Setting $event->setUsed(true) prevent the following message for the affected content element, setting it to false displays it:

Example: Display "Unused elements detected on this page" for elements with missing parent

EXT:my_extension/Classes/Listener/ContentUsedOnPage.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Listener;

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

#[AsEventListener(
    identifier: 'my-extension/view/content-used-on-page',
)]
final readonly class ContentUsedOnPage
{
    public function __invoke(IsContentUsedOnPageLayoutEvent $event): void
    {
        // Get the current record from the event.
        $record = $event->getRecord();

        // This code will be your domain logic to indicate if content
        // should be hidden in the page module.
        if ((int)($record['colPos'] ?? 0) === 999
            && !empty($record['tx_myext_content_parent'])
        ) {
            // Flag the current element as not used. Set it to true, if you
            // want to flag it as used and hide it from the page module.
            $event->setUsed(false);
        }
    }
}
Copied!

New in version 13.0

API of IsContentUsedOnPageLayoutEvent

class IsContentUsedOnPageLayoutEvent
Fully qualified name
\TYPO3\CMS\Backend\View\Event\IsContentUsedOnPageLayoutEvent

Use this Event to identify whether a content element is used.

getRecord ( )
Returns
array
isRecordUsed ( )
Returns
bool
setUsed ( bool $isUsed)
param $isUsed

the isUsed

getKnownColumnPositionNumbers ( )
Returns
array
getPageLayoutContext ( )
Returns
\TYPO3\CMS\Backend\View\PageLayoutContext