AfterPageTreeItemsPreparedEvent

New in version 12.0: This PSR-14 event replaces the following hooks:

  • $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Workspaces\Service\WorkspaceService']['hasPageRecordVersions']

  • $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Workspaces\Service\WorkspaceService']['fetchPagesWithVersionsInTable']

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

It is dispatched in the \TYPO3\CMS\Backend\Controller\Page\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.

Example

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\Core\Attribute\AsEventListener;

#[AsEventListener(
    identifier: 'my-extension/backend/modify-page-tree-items'
)]
final class MyEventListener
{
    public function __invoke(AfterPageTreeItemsPreparedEvent $event): void
    {
        $items = $event->getItems();
        foreach ($items as $item) {
            // Setting special item for page with id 123
            if ($item['_page']['uid'] === 123) {
                $item['icon'] = 'my-special-icon';
            }
        }
        $event->setItems($items);
    }
}

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\Controller\Event\AfterPageTreeItemsPreparedEvent

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

getRequest()
Return type

Psr\Http\Message\ServerRequestInterface

getItems()
Return type

array

setItems(array $items)
Parameters
  • $items (array) -- the items