ds-site/Classes/Hooks/Backend/PageLayoutHeader.php

90 lines
2.9 KiB
PHP
Raw Normal View History

<?php
namespace DanielSiepmann\DsSite\Hooks\Backend;
/*
* Copyright (C) 2019 Daniel Siepmann <coding@daniel-siepmann.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
use TYPO3\CMS\Backend\Controller\PageLayoutController;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Frontend\Resource\FileCollector;
class PageLayoutHeader
{
/**
* @var PageLayoutController
*/
private $pageLayoutController;
public function render(
array $params,
PageLayoutController $pageLayoutController
): string {
$this->pageLayoutController = $pageLayoutController;
$view = $this->getView();
$view->assignMultiple([
'record' => $this->pageLayoutController->pageinfo,
'metaInfo' => [
[
'label' => 'introduction',
'value' => $this->pageLayoutController->pageinfo['abstract'],
'field' => 'abstract',
'type' => 'string',
],
[
'label' => 'published',
'value' => $this->pageLayoutController->pageinfo['lastUpdated'],
'field' => 'lastUpdated',
'type' => 'date',
],
[
'label' => 'updated',
'value' => $this->pageLayoutController->pageinfo['SYS_LASTCHANGED'],
'type' => 'date',
],
[
'label' => 'media',
'value' => $this->resolvePageMedia(),
'field' => 'media',
'type' => 'files',
],
],
]);
$view->setTemplatePathAndFilename('EXT:ds_site/Resources/Private/Templates/Backend/Page/MetaInfo.html');
return $view->render();
}
private function getView(): StandaloneView
{
return GeneralUtility::makeInstance(StandaloneView::class);
}
private function resolvePageMedia(): array
{
$page = ['uid' => $this->pageLayoutController->pageinfo['uid']];
$files = new FileCollector();
$files->addFilesFromRelation('pages', 'media', $page);
return $files->getFiles();
}
}