BeforePageTreeIsFilteredEvent

New in version 14.0

This PSR-14 event was introduced to add custom functionality and advanced evaluations to the the page tree filter.

The PSR-14 \TYPO3\CMS\Backend\Tree\Repository\BeforePageTreeIsFilteredEvent allows developers to extend the page trees filter's functionality and process the given search phrase in more advanced ways.

The page tree is one of the central components in the TYPO3 backend, particularly for editors. However, in large installations, the page tree can quickly become overwhelming and difficult to navigate. To maintain a clear overview, the page tree can be filtered using basic terms, such as the page title or ID.

Example: Add evaluation of document types to the page tree search filter

The event listener class, using the PHP attribute #[AsEventListener] for registration, adds additional conditions to the filter.

EXT:my_extension/Classes/Backend/EventListener/MyEventListener.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Frontend\EventListener;

use TYPO3\CMS\Backend\Tree\Repository\BeforePageTreeIsFilteredEvent;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Database\Connection;

final class MyEventListener
{
    #[AsEventListener]
    public function removeFetchedPageContent(BeforePageTreeIsFilteredEvent $event): void
    {
        // Adds another uid to the filter
        $event->searchUids[] = 123;

        // Adds evaluation of doktypes to the filter
        if (preg_match('/doktype:([0-9]+)/i', $event->searchPhrase, $match)) {
            $doktype = $match[1];
            $event->searchParts = $event->searchParts->with(
                $event->queryBuilder->expr()->eq(
                    'doktype',
                    $event->queryBuilder->createNamedParameter($doktype, Connection::PARAM_INT),
                ),
            );
        }
    }
}
Copied!

BeforePageTreeIsFilteredEvent API

The event provides the following member properties:

$searchParts:
The search parts to be used for filtering
$searchUids:
The uids to be used for filtering by a special search part, which is added by Core always after listener evaluation
$searchPhrase
The complete search phrase, as entered by the user
$queryBuilder:
The current QueryBuilder
class BeforePageTreeIsFilteredEvent
Fully qualified name
\TYPO3\CMS\Backend\Tree\Repository\BeforePageTreeIsFilteredEvent

Listeners to this event will be able to modify the search parts, to be used to filter the page tree

public searchParts
public searchUids
public readonly searchPhrase
public readonly queryBuilder