Commit 6c3a9737 authored by Oliver Bartsch's avatar Oliver Bartsch Committed by Daniel Goerz
Browse files

[FEATURE] Add getModuleTemplate to PageLayoutController

This allows to access the ModuleTemplate instance
in PageLayoutController related hooks and therefore
enables extension authors to be more flexible when
manipulating the page module view.

Resolves: #92358
Releases: master
Change-Id: I6f3d370d0c8d730dfcdf631d8516a8691360167b
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69396

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Jochen's avatarJochen <rothjochen@gmail.com>
Tested-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Jochen's avatarJochen <rothjochen@gmail.com>
Reviewed-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
parent 15a44f39
......@@ -707,6 +707,16 @@ class PageLayoutController
return $content;
}
/**
* Make the ModuleTemplate public accessible for the use in hooks.
*
* @return ModuleTemplate
*/
public function getModuleTemplate(): ModuleTemplate
{
return $this->moduleTemplate;
}
/***************************
*
* Sub-content functions, rendering specific parts of the module content.
......
.. include:: ../../Includes.txt
=================================================================
Feature: #92358 - Add getModuleTemplate() to PageLayoutController
=================================================================
See :issue:`92358`
Description
===========
The :php:`PageLayoutController` features two hooks for manipulating the
Page module. `drawHeaderHook` and `drawFooterHook`. Those hooks already
receive the parent object :php:`PageLayoutController`. Since the calling
code expects the hooks to return additional content, it was previously
not possible to change other parts of the module, e.g. the module header.
To give developers more possibilities in manipulating the page module,
using the mentioned hooks, the parent object now contains a new getter
method :php:`getModuleTemplate()`. It can for example be used to add an
additional button to the modules' button bar.
.. code-block:: php
public function drawHeaderHook(array $parameters, PageLayoutController $parentObject)
{
$moduleTemplate = $parentObject->getModuleTemplate();
$buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();
$linkButton = $buttonBar
->makeLinkButton()
->setHref('/typo3/some/url')
->setTitle('My custom button')
->setClasses('custom-link-class')
->setIcon($moduleTemplate->getIconFactory()->getIcon('actions-link', Icon::SIZE_SMALL));
$buttonBar->addButton($linkButton);
}
Impact
======
When using either the `drawHeaderHook` or the `drawFooterHook` of the
:php:`PageLayoutController`, the provided parent object now contains
the :php:`getModuleTemplate()` method, which can be used to retrieve
the corresponding :php:`ModuleTemplate` instance. This provides
more flexibility to 3rd party code manipulating the page module view.
.. index:: Backend, PHP-API, ext:backend
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment