IsContentUsedOnPageLayoutEvent¶
New in version 12.0
This event TYPO3\CMS\Backend\View\Event\IsContentUsedOnPageLayoutEvent
serves as a drop-in replacement for the removed
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['record_is_used']
hook.
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.
Example¶
<?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);
}
}
}
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, or if you
need to be compatible with older TYPO3 versions, you can also register an
event listener via the Configuration/Services.yaml
file. Switch to
an older version of this page for an example or have a look at the section
Implementing an event listener in your extension.
API¶
- class \TYPO3\CMS\Backend\View\Event\ IsContentUsedOnPageLayoutEvent¶
-
Use this Event to identify whether a content element is used.
- getRecord ( ) ¶
-
- returntype
-
array
- isRecordUsed ( ) ¶
-
- returntype
-
bool
- setUsed ( bool $isUsed) ¶
-
- param bool $isUsed
-
the isUsed
- getKnownColumnPositionNumbers ( ) ¶
-
- returntype
-
array
- getPageLayoutContext ( ) ¶
-
- returntype
-
TYPO3\CMS\Backend\View\PageLayoutContext