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

View file

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

View file

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