Use PageLayoutHeader hook instead of new PageLayoutView hook

Do not overcomplicate the implementation.
Just add page info to rendered page.
This commit is contained in:
Daniel Siepmann 2020-01-08 19:15:08 +01:00
parent eac3061c0d
commit 1279334ed1
3 changed files with 20 additions and 41 deletions

View file

@ -1,6 +1,6 @@
<?php
namespace DanielSiepmann\DsSite\Hooks\View;
namespace DanielSiepmann\DsSite\Hooks\Backend;
/*
* Copyright (C) 2019 Daniel Siepmann <coding@daniel-siepmann.de>
@ -21,56 +21,43 @@ namespace DanielSiepmann\DsSite\Hooks\View;
* 02110-1301, USA.
*/
use TYPO3\CMS\Backend\View\PageLayoutView as Typo3PageLayoutView;
use TYPO3\CMS\Backend\Controller\PageLayoutController;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Frontend\Resource\FileCollector;
/**
* Holds all TYPO3 Hooks for PageLayoutView class.
*/
class PageLayoutView
class PageLayoutHeader
{
/**
* @var Typo3PageLayoutView
* @var PageLayoutController
*/
private $layoutView;
private $pageLayoutController;
public function processColPosGrid(
Typo3PageLayoutView $layoutView,
array $columnConfig
public function render(
array $params,
PageLayoutController $pageLayoutController
): string {
$this->layoutView = $layoutView;
if (isset($columnConfig['colPos']) && trim($columnConfig['colPos']) !== '') {
return '';
}
$this->pageLayoutController = $pageLayoutController;
if (isset($columnConfig['name']) && $columnConfig['name'] === 'Meta Info') {
return $this->renderMetaInfo();
}
}
private function renderMetaInfo(): string
{
$view = $this->getView();
$view->assignMultiple([
'record' => $this->layoutView->pageRecord,
'record' => $this->pageLayoutController->pageinfo,
'metaInfo' => [
[
'label' => 'introduction',
'value' => $this->layoutView->pageRecord['abstract'],
'value' => $this->pageLayoutController->pageinfo['abstract'],
'field' => 'abstract',
'type' => 'string',
],
[
'label' => 'published',
'value' => $this->layoutView->pageRecord['lastUpdated'],
'value' => $this->pageLayoutController->pageinfo['lastUpdated'],
'field' => 'lastUpdated',
'type' => 'date',
],
[
'label' => 'updated',
'value' => $this->layoutView->pageRecord['SYS_LASTCHANGED'],
'value' => $this->pageLayoutController->pageinfo['SYS_LASTCHANGED'],
'type' => 'date',
],
[
@ -93,7 +80,7 @@ class PageLayoutView
private function resolvePageMedia(): array
{
$page = ['uid' => $this->layoutView->pageRecord['uid']];
$page = ['uid' => $this->pageLayoutController->pageinfo['uid']];
$files = new FileCollector();
$files->addFilesFromRelation('pages', 'media', $page);

View file

@ -8,14 +8,6 @@ mod.web_layout.BackendLayouts {
rowCount = 5
rows {
1 {
columns {
1 {
name = Meta Info
colPos =
}
}
}
2 {
columns {
1 {
name = Introduction
@ -23,7 +15,7 @@ mod.web_layout.BackendLayouts {
}
}
}
3 {
2 {
columns {
1 {
name = Content
@ -31,7 +23,7 @@ mod.web_layout.BackendLayouts {
}
}
}
4 {
3 {
columns {
1 {
name = Acknowledgements
@ -39,7 +31,7 @@ mod.web_layout.BackendLayouts {
}
}
}
5 {
4 {
columns {
1 {
name = Further reading

View file

@ -8,9 +8,9 @@
],
],
'SC_OPTIONS' => [
'cms/layout/class.tx_cms_layout.php' => [
'colpos_content' => [
$extKey => \DanielSiepmann\DsSite\Hooks\View\PageLayoutView::class,
'cms/layout/db_layout.php' => [
'drawHeaderHook' => [
$extKey => \DanielSiepmann\DsSite\Hooks\Backend\PageLayoutHeader::class . '->render',
],
],
],