ModifyPageLayoutContentEvent

New in version 12.0.

Event for modifying page module content.

This event features the methods getRequest(), getModuleTemplate() and additional getters and setters for the header and footer content.

It is possible to add additional content, overwrite existing content or reorder the content.

Example

Registration of the event in your extension's Services.yaml:

EXT:my_extension/Configuration/Services.yaml
Vendor\MyExtension\Backend\MyEventListener:
  tags:
    - name: event.listener
      identifier: 'my-package/backend/modify-page-module-content'

The corresponding event listener class:

EXT:my_extension/Classes/Backend/EventListener/MyEventListener.php
namespace Vendor\MyExtension\Backend\MyEventListener;

use TYPO3\CMS\Backend\Controller\Event\ModifyPageLayoutContentEvent;

final class MyEventListener {

    public function __invoke(ModifyPageLayoutContentEvent $event): void
    {
        $event->addHeaderContent('Additional header content');

        $event->setFooterContent('Overwrite footer content');
    }
}

API

class TYPO3\CMS\Backend\Controller\Event\ModifyPageLayoutContentEvent

Listeners to this Event will be able to modify the header and footer content of the page module

getRequest()
Return type

Psr\Http\Message\ServerRequestInterface

getModuleTemplate()
Return type

TYPO3\CMS\Backend\Template\ModuleTemplate

setHeaderContent(string $content)

Set content for the header. Can also be used to e.g. reorder existing content.

IMPORTANT: This overwrites existing content from previous listeners!

Parameters
  • $content (string) -- the content

addHeaderContent(string $content)

Add additional content to the header

Parameters
  • $content (string) -- the content

getHeaderContent()
Return type

string

setFooterContent(string $content)

Set content for the footer. Can also be used to e.g. reorder existing content.

IMPORTANT: This overwrites existing content from previous listeners!

Parameters
  • $content (string) -- the content

addFooterContent(string $content)

Add additional content to the footer

Parameters
  • $content (string) -- the content

getFooterContent()
Return type

string

History / Migration

The event TYPO3\CMS\Backend\Controller\Event\ModifyPageLayoutContentEvent has been introduced to serve as a more powerful and flexible alternative for the removed hooks $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'] and $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook'].

In contrast to the removed hooks, this event does not provide the PageLayoutController as $parentObject, since getModuleTemplate() has been the only public method, which is now directly included in the event.

Additionally, there were three public properties $id, $pageInfo and $MOD_SETTINGS, which had been marked as @internal in TYPO3 v9. If needed, the information can be retrieved from the request directly.

An example to get the current $id:

public function __invoke(ModifyPageLayoutContentEvent $event): void
{
    $id = (int)($event->getRequest()->getQueryParams()['id'] ?? 0);
}