AfterContentHasBeenFetchedEvent
New in version 13.4.2 / 14.0
Using the PSR-14 \TYPO3\
,
it is possible to manipulate the page content, which has been fetched by the
page-content data processor,
based on the page layout and corresponding columns configuration.
Example
The event listener class, using the PHP attribute #
for
registration, removes some of the fetched page content elements based on
specific field values.
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Frontend\EventListener;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Frontend\Event\AfterContentHasBeenFetchedEvent;
final readonly class MyEventListener
{
#[AsEventListener]
public function removeFetchedPageContent(AfterContentHasBeenFetchedEvent $event): void
{
foreach ($event->groupedContent as $columnIdentifier => $column) {
foreach ($column['records'] ?? [] as $key => $record) {
if ($record->has('parent_field_name') && (int)($record->get('parent_field_name') ?? 0) > 0) {
unset($event->groupedContent[$columnIdentifier]['records'][$key]);
}
}
}
}
}