Last active
October 11, 2024 10:53
-
-
Save kitzberger/e5954e5d349b90123fdf2ce97b78e7d9 to your computer and use it in GitHub Desktop.
TYPO3 PageModule Enhancements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
TYPO3 12+ | |
Registration in Services.yaml | |
See https://docs.typo3.org/m/typo3/reference-coreapi/12.4/en-us/ApiOverview/Events/Events/Backend/ModifyPageLayoutContentEvent.html | |
*/ | |
declare(strict_types=1); | |
namespace My\Extension\EventListener; | |
use TYPO3\CMS\Backend\Controller\Event\ModifyPageLayoutContentEvent; | |
use TYPO3\CMS\Backend\View\BackendLayoutView; | |
use TYPO3\CMS\Core\Utility\GeneralUtility; | |
final class PageModuleEventListener | |
{ | |
public function __invoke(ModifyPageLayoutContentEvent $event): void | |
{ | |
// Get the current page ID | |
$id = (int)($event->getRequest()->getQueryParams()['id'] ?? 0); | |
$beLayout = GeneralUtility::makeInstance(BackendLayoutView::class)->getBackendLayoutForPage($id); | |
$beLayoutTitle = $beLayout->getTitle(); | |
$beLayoutTitle = $GLOBALS['LANG']->sL($beLayoutTitle) ?? $beLayoutTitle; | |
$event->addHeaderContent('<h3>Page info</h3><p><b>FE-Layout:</b> ' . $layoutTitle . '<br><b>BE-Layout:</b> ' . $beLayoutTitle . '</p>'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
TYPO3 10+11 | |
Registration in ext_localconf.php: | |
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'][] = \My\Extension\Hooks\PageModuleHook::class . '->info'; | |
*/ | |
namespace My\Extension\Hooks; | |
use TYPO3\CMS\Backend\Controller\PageLayoutController; | |
use TYPO3\CMS\Backend\View\BackendLayoutView; | |
use TYPO3\CMS\Core\Utility\GeneralUtility; | |
class PageModuleHook | |
{ | |
public function info(array $params, PageLayoutController $controller) | |
{ | |
$beLayout = GeneralUtility::makeInstance(BackendLayoutView::class)->getBackendLayoutForPage($controller->id); | |
$beLayoutTitle = $beLayout->getTitle(); | |
$beLayoutTitle = $GLOBALS['LANG']->sL($beLayoutTitle) ?? $beLayoutTitle; | |
return '<h3>BE-Layout: ' . $beLayoutTitle . '</h3>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment