DocHeaderComponent 

The \TYPO3\CMS\Backend\Template\Components\DocHeaderComponent can be used to display a standardized header section in a backend module with buttons, menus etc. It can also be used to hide the header section in case it is not desired to display it.

The module header displayed by the DocHeaderComponent

You can get the DocHeaderComponent with \TYPO3\CMS\Backend\Template\ModuleTemplate::getDocHeaderComponent from your module template.

DocHeaderComponent API 

It has the following methods:

class DocHeaderComponent
Fully qualified name
\TYPO3\CMS\Backend\Template\Components\DocHeaderComponent

Document header component for backend modules.

This component manages the header area of backend module views, providing: - Breadcrumb navigation (via BreadcrumbContext) - Button bar for action buttons (save, close, delete, etc.) - Drop-down menus for module-specific actions

The component can be enabled or disabled to control visibility of the entire document header. It integrates with the ModuleTemplate to provide a consistent header across all backend modules.

Usage in a controller:

public function __construct(
    protected readonly ComponentFactory $componentFactory,
) }

public function myAction(): ResponseInterface
{
    $view = $this->moduleTemplateFactory->create($request);
    $docHeader = $view->getDocHeaderComponent();

    // Set breadcrumb for a page
    $docHeader->setPageBreadcrumb($pageInfo);

    // Add action buttons using ComponentFactory
    $buttonBar = $docHeader->getButtonBar();
    $saveButton = $this->componentFactory->createSaveButton('editform');
    $buttonBar->addButton($saveButton, ButtonBar::BUTTON_POSITION_LEFT, 1);
}
Copied!
setMetaInformation ( array $metaInformation)

Deprecated: since v14, will be removed in v15. Use setPageBreadcrumb() instead.

Set page information

param $metaInformation

Record array

setMetaInformationForResource ( \TYPO3\CMS\Core\Resource\ResourceInterface $resource)

Deprecated: since v14, will be removed in v15. Use setResourceBreadcrumb() instead.

Set meta information for a file/folder resource.

param $resource

the resource

setBreadcrumbContext ( ?\TYPO3\CMS\Backend\Breadcrumb\BreadcrumbContext $breadcrumbContext)

Sets the breadcrumb context for rendering.

This is the main API for providing breadcrumb information.

For common scenarios, use the convenience methods instead: - setPageBreadcrumb() for page records - setRecordBreadcrumb() for any record - setResourceBreadcrumb() for files or folders

param $breadcrumbContext

The breadcrumb context

setPageBreadcrumb ( array $pageRecord)

Sets breadcrumb from a page record array.

This is the direct replacement for setMetaInformation().

Example:
$view->getDocHeaderComponent()->setPageBreadcrumb($pageInfo);
param $pageRecord

The page record array (must contain 'uid')

setRecordBreadcrumb ( string $table, int $uid)

Sets breadcrumb for editing a record.

Example: $view->getDocHeaderComponent()->setRecordBreadcrumb('tt_content', 123);

param $table

The table name

param $uid

The record UID

setResourceBreadcrumb ( \TYPO3\CMS\Core\Resource\ResourceInterface $resource)

Sets breadcrumb for any resource (file or folder).

Example: $view->getDocHeaderComponent()->setResourceBreadcrumb($file); $view->getDocHeaderComponent()->setResourceBreadcrumb($folder);

param $resource

The resource (file or folder)

addBreadcrumbSuffixNode ( \TYPO3\CMS\Backend\Dto\Breadcrumb\BreadcrumbNode $node)

Adds a suffix node to the current breadcrumb context.

Suffix nodes are appended after the main breadcrumb trail and are useful for: - Indicating "Create New" actions - Showing "Edit Multiple" states - Adding custom contextual information

Example:

$docHeader->setPageBreadcrumb($pageInfo); $docHeader->addBreadcrumbSuffixNode( new BreadcrumbNode( identifier: 'new', label: 'Create New Content Element', icon: 'actions-add' ) );

Note: This creates or modifies the breadcrumb context. If you need to build a complete context, use BreadcrumbFactory instead.

param $node

The node to append

getMenuRegistry ( )

Returns the menu registry for adding drop-down menus to the document header.

Returns
\TYPO3\CMS\Backend\Template\Components\MenuRegistry
getButtonBar ( )

Returns the button bar for adding action buttons to the document header.

The button bar supports multiple button positions (left, right) and groups to organize buttons logically.

Returns
\TYPO3\CMS\Backend\Template\Components\ButtonBar
isEnabled ( )

Determines whether this component is enabled and should be rendered.

When disabled, the entire document header (including breadcrumbs, buttons, and menus) will not be displayed in the backend module.

Returns
bool
enable ( )

Enables this component for rendering.

disable ( )

Disables this component to prevent rendering.

docHeaderContent ( ?\Psr\Http\Message\ServerRequestInterface $request)

Returns the complete document header content as an array for rendering.

This method aggregates all components (buttons, menus, breadcrumbs) into a structured array that can be consumed by the Fluid template rendering the backend module layout.

The returned array structure: - 'enabled': Whether the document header should be rendered - 'buttons': Array of button configurations from the button bar - 'menus': Array of menu configurations from the menu registry - 'breadcrumb': Breadcrumb trail data from the breadcrumb context

param $request

the request

Returns
array

Example: Build a module header with buttons and a menu 

The following example is extracted from the example Extbase extension t3docs/blog-example . See the complete source code at t3doc/blog-example (GitHub).

We use the DocHeaderComponent to register buttons and a menu to the module header.

Class T3docs\BlogExample\Controller\BackendController
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Template\ModuleTemplate;

class BackendController extends ActionController
{
    private function modifyDocHeaderComponent(ModuleTemplate $view, string &$context): void
    {
        $menu = $this->buildMenu($view, $context);
        $view->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);

        $buttonBar = $view->getDocHeaderComponent()->getButtonBar();
        $this->addButtons($buttonBar);

        $metaInformation = $this->getMetaInformation();
        if (is_array($metaInformation)) {
            $view->getDocHeaderComponent()->setMetaInformation($metaInformation);
        }
    }

    protected function initializeModuleTemplate(
        ServerRequestInterface $request,
    ): ModuleTemplate {
        $view = $this->moduleTemplateFactory->create($request);

        $context = '';
        $this->modifyDocHeaderComponent($view, $context);
        $view->setFlashMessageQueue($this->getFlashMessageQueue());
        $view->setTitle(
            $this->getLanguageService()->sL('blog_example.module.mod:mlang_tabs_tab'),
            $context,
        );

        return $view;
    }
}
Copied!