AfterPageTreeItemsPreparedEvent 

The PSR-14 event \TYPO3\CMS\Backend\Controller\Event\AfterPageTreeItemsPreparedEvent allows prepared page tree items to be modified.

It is dispatched in the TreeController class after the page tree items have been resolved and prepared. The event provides the current PSR-7 request object as well as the page tree items. All items contain the corresponding page record in the special _page key.

The event also provides the current page tree search query via getSearchQuery() , returning the search phrase used to filter the page tree, or null if no search is currently active. The event can be dispatched in contexts without a PSR-7 request, so getRequest() - and therefore its return value - is nullable as well.

Labels 

Tree node labels can be defined which offer customizable color markings for tree nodes. They also require an associated label for improved accessibility. Each node can support multiple labels, sorted by priority, with the highest priority label taking precedence over others.

A label can also be assigned to a node via user TSconfig. Please note that only the marker for the label with the highest priority is rendered. All additional labels will only be added to the title of the node.

Status information 

Tree nodes can incorporate status information. These details serve to indicate the status of nodes and provide supplementary information. For instance, if a page undergoes changes within a workspace, it will display an indicator on the respective tree node. Additionally, the status is appended to the node's title. This not only improves visual clarity but also enhances information accessibility.

Each node can accommodate multiple status information, prioritized by severity and urgency. Critical messages take precedence over other status notifications.

Example: Change the icon and add a label to pages in the page tree 

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

declare(strict_types=1);

namespace MyVendor\MyExtension\Backend\EventListener;

use TYPO3\CMS\Backend\Controller\Event\AfterPageTreeItemsPreparedEvent;
use TYPO3\CMS\Backend\Dto\Tree\Label\Label;
use TYPO3\CMS\Backend\Dto\Tree\Status\StatusInformation;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;

#[AsEventListener(
  identifier: 'my-extension/backend/modify-page-tree-items',
)]
final readonly class MyEventListener
{
  public function __invoke(AfterPageTreeItemsPreparedEvent $event): void
  {
    $searchQuery = $event->getSearchQuery();

    $items = $event->getItems();
    foreach ($items as &$item) {
      if (($item['_page']['pid'] ?? null) === 123) {
        // Set special icon for page with ID 123
        $item['icon'] = 'my-special-icon';

        // Set a tree node label
        $item['labels'][] = new Label(
          label: 'Campaign B',
          color: '#00658f',
          priority: 1,
        );

        // Set a status information
        $item['statusInformation'][] = new StatusInformation(
          label: 'A warning message',
          severity: ContextualFeedbackSeverity::WARNING,
          priority: 0,
          icon: 'actions-dot',
          overlayIcon: '',
        );
      }

      // Indicate which items matched an active page tree search
      if ($searchQuery !== null) {
        $item['statusInformation'][] = new StatusInformation(
          label: sprintf('Matched search "%s"', $searchQuery),
          severity: ContextualFeedbackSeverity::INFO,
          priority: 0,
          icon: 'actions-search',
          overlayIcon: '',
        );
      }
    }
    $event->setItems($items);
  }
}
Copied!

API 

final class AfterPageTreeItemsPreparedEvent
Fully qualified name
\TYPO3\CMS\Backend\Controller\Event\AfterPageTreeItemsPreparedEvent

Listeners to this event will be able to modify the prepared page tree items for the page tree

getRequest()
Returns
?\Psr\Http\Message\ServerRequestInterface
getSearchQuery()
Returns
?string
getItems()
Returns
array
setItems(array $items)
param $items

the items