Add page meta info to page layout for blog posts

This commit is contained in:
Daniel Siepmann 2019-12-13 12:09:08 +01:00
parent da21d13416
commit 217cb21e70
6 changed files with 273 additions and 8 deletions

View file

@ -0,0 +1,86 @@
<?php
namespace DanielSiepmann\DsSite\Hooks\View;
/*
* 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\View\PageLayoutView as Typo3PageLayoutView;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
/**
* Holds all TYPO3 Hooks for PageLayoutView class.
*/
class PageLayoutView
{
/**
* @var Typo3PageLayoutView
*/
private $layoutView;
public function processColPosGrid(
Typo3PageLayoutView $layoutView,
array $columnConfig
): string {
$this->layoutView = $layoutView;
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->assignMultiple([
'record' => $this->layoutView->pageRecord,
'metaInfo' => [
[
'label' => 'introduction',
'value' => $this->layoutView->pageRecord['abstract'],
'field' => 'abstract',
'type' => 'string',
],
[
'label' => 'published',
'value' => $this->layoutView->pageRecord['lastUpdated'],
'field' => 'lastUpdated',
'type' => 'date',
],
[
'label' => 'updated',
'value' => $this->layoutView->pageRecord['SYS_LASTCHANGED'],
'type' => 'date',
],
],
]);
$view->setTemplatePathAndFilename('EXT:ds_site/Resources/Private/Templates/Backend/Page/MetaInfo.html');
return $view->render();
}
private function getView(): StandaloneView
{
return GeneralUtility::makeInstance(StandaloneView::class);
}
}

View file

@ -0,0 +1,82 @@
<?php
namespace DanielSiepmann\DsSite\ViewHelpers\Uri;
/*
* 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\Routing\UriBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
/**
* Use this ViewHelper to provide edit links (only the uri) to records. The ViewHelper will
* pass the uid and table to FormEngine.
*
* The uid must be given as a positive integer.
* For new records, use the :ref:`<be:uri.newRecord> <typo3-backend-uri-newrecord>`.
*
* Examples
* ========
*
* URI to the record-edit action passed to FormEngine::
*
* <be:uri.editRecord uid="42" table="a_table" returnUrl="foo/bar" />
*
* ``/typo3/index.php?route=/record/edit&edit[a_table][42]=edit&returnUrl=foo/bar``
*/
class EditRecordViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;
public function initializeArguments()
{
$this->registerArgument('uid', 'int', 'uid of record to be edited, 0 for creation', true);
$this->registerArgument('table', 'string', 'target database table', true);
$this->registerArgument('returnUrl', 'string', '', false, '');
$this->registerArgument('columns', 'string', 'columns to show', false, '');
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
*
* @return string
* @throws \TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
{
if ($arguments['uid'] < 1) {
throw new \InvalidArgumentException('Uid must be a positive integer, ' . $arguments['uid'] . ' given.', 1526128259);
}
if (empty($arguments['returnUrl'])) {
$arguments['returnUrl'] = GeneralUtility::getIndpEnv('REQUEST_URI');
}
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
return (string)$uriBuilder->buildUriFromRoute('record_edit', [
'edit' => [$arguments['table'] => [$arguments['uid'] => 'edit']],
'columnsOnly' => $arguments['columns'],
'returnUrl' => $arguments['returnUrl']
]);
}
}

View file

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

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.0" xmlns:t3="http://typo3.org/schemas/xliff">
<file source-language="en" datatype="plaintext">
<header/>
<body>
<trans-unit id="backend.page.metainfo.notSet">
<source>not set</source>
</trans-unit>
<trans-unit id="backend.page.metainfo.introduction">
<source>Introduction (Abstract)</source>
</trans-unit>
<trans-unit id="backend.page.metainfo.published">
<source>Published (Last Updated)</source>
</trans-unit>
<trans-unit id="backend.page.metainfo.updated">
<source>Updated (SYS_LASTCHANGED)</source>
</trans-unit>
</body>
</file>
</xliff>

View file

@ -0,0 +1,45 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
data-namespace-typo3-fluid="true">
<div class="t3-page-ce-wrapper t3-page-ce-empty">
<div class="t3-page-ce t3js-page-ce">
<div class="t3js-page-new-ce t3-page-ce-wrapper-new-ce">
<f:for each="{metaInfo}" as="info">
<a href="{f:render(section: 'Link', arguments: {recordUid: record.uid, field: info.field}) -> f:spaceless()}">
<h3>{info.label -> f:translate(id: 'backend.page.metainfo.{info.label}', extensionName: 'DsSite')}</h3>
<p>{f:render(section: 'Value-{info.type}', arguments: {value: info.value, type: info.type}) -> f:spaceless()}</p>
</a>
</f:for>
</div>
</div>
</div>
<f:section name="Value-string">
<f:if condition="{value}">
<f:then>
{value}
</f:then>
<f:else>
{f:translate(id: 'backend.page.metainfo.notSet', extensionName: 'DsSite')}
</f:else>
</f:if>
</f:section>
<f:section name="Value-date">
<f:if condition="{value} == 0">
<f:then>
{f:translate(id: 'backend.page.metainfo.notSet', extensionName: 'DsSite')}
</f:then>
<f:else>
{value -> f:format.date(format: 'd.m.Y')}
</f:else>
</f:if>
</f:section>
<f:section name="Link">
{f:uri.editRecord(
uid: recordUid,
table: 'pages',
columns: field
)}
</f:section>
</html>

View file

@ -1,6 +1,30 @@
<?php <?php
$GLOBALS['TYPO3_CONF_VARS']['RTE']['Presets']['default'] = 'EXT:ds_site/Configuration/RTE/Default.yaml'; (function (string $extKey) {
\TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($GLOBALS['TYPO3_CONF_VARS'], [
'RTE' => [
'Presets' => [
'default' => 'EXT:ds_site/Configuration/RTE/Default.yaml',
],
],
'SC_OPTIONS' => [
'cms/layout/class.tx_cms_layout.php' => [
'colpos_content' => [
$extKey => \DanielSiepmann\DsSite\Hooks\View\PageLayoutView::class,
],
],
],
'SYS' => [
'fluid' => [
'namespaces' => [
'f' => [
$extKey => 'DanielSiepmann\DsSite\ViewHelpers',
],
],
],
],
]);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addUserTSConfig( \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addUserTSConfig(
"@import 'EXT:ds_site/Configuration/UserTSconfig/*.tsconfig'" "@import 'EXT:ds_site/Configuration/UserTSconfig/*.tsconfig'"
); );
})('ds_site');