Skip to content
Snippets Groups Projects
Commit 7801c702 authored by Tim Wagner's avatar Tim Wagner
Browse files

[TASK] Create backend preview for news overview plugin

parent 9226b1ea
No related branches found
No related tags found
1 merge request!24[FEATURE] Plugin Backend Previews
<?php
namespace SGalinski\SgNews\Hooks\PageLayoutView;
/***************************************************************
* Copyright notice
* (c) sgalinski Internet Services (https://www.sgalinski.de)
* All rights reserved
* This script is part of the TYPO3 project. The TYPO3 project 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 3 of the License, or
* (at your option) any later version.
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* This script 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.
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
/**
* Class PluginRenderer
*
* @package SGalinski\SgNews\Hook\PagelayoutView\PluginRenderer
*/
class PluginRenderer implements PageLayoutViewDrawItemHookInterface {
/**
* Preprocesses the preview rendering of an sg_news content element plugin.
*
* @param PageLayoutView $parentObject Calling parent object
* @param bool $drawItem Whether to draw the item using the default functionalities
* @param string $headerContent Header content
* @param string $itemContent Item content
* @param array $row Record row of tt_content
* @noinspection ReferencingObjectsInspection
*/
public function preProcess(
PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row
): void {
switch ($row['list_type']) {
case 'sgnews_overview':
$drawItem = FALSE;
$view = $this->createViewWithTemplate('Overview');
$view->assign('uid', $row['uid']);
$this->adaptPluginHeaderContent($headerContent, $row);
// Get available plugin settings and their values from flexform
$pluginConfiguration = GeneralUtility::xml2array(
$row['pi_flexform'], 'T3DataStructure'
)['data']['main']['lDEF'];
$templateData = [
'groupBy' => $pluginConfiguration['settings.groupBy']['vDEF'],
'enableFilter' => $pluginConfiguration['settings.enableFilter']['vDEF'],
'newsLimit' => $pluginConfiguration['settings.newsLimit']['vDEF'],
'onlyNewsWithinThisPageSection' => $pluginConfiguration['settings.onlyNewsWithinThisPageSection']['vDEF'],
'starttime' => $pluginConfiguration['settings.starttime']['vDEF'],
'endtime' => $pluginConfiguration['settings.endtime']['vDEF'],
'sortBy' => $pluginConfiguration['settings.sortBy']['vDEF'],
'sortDirection' => $pluginConfiguration['settings.sortDirection']['vDEF']
];
$view->assign('data', $templateData);
$itemContent .= $view->render();
break;
default:
// No need to do anything
}
}
/**
* Creates a new StandaloneView object with template and partial rot paths,
* attaches the template with the given name to it and returns it.
*
* @param string $templateName
* @return StandaloneView
*/
protected
function createViewWithTemplate(
string $templateName
): StandaloneView {
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplateRootPaths(['EXT:sg_news/Resources/Private/Templates/Backend']);
$view->setPartialRootPaths(['EXT:sg_news/Resources/Private/Partials/Backend']);
if (!str_ends_with($templateName, '.html')) {
$templateName .= '.html';
}
$view->setTemplate($templateName);
return $view;
}
/**
* Adapts the given $headerContent.
* To be used in all plugin previews so the Header Contents appear similarly.
*
* @param $headerContent
* @param $row
*/
protected
function adaptPluginHeaderContent(&$headerContent, $row): void {
$headerContent = '<h4>' . $this->getPluginNameForHeaderContent(
(int) $row['pid'], $row['list_type']
) . $headerContent . '</h4>';
}
/**
* Finds the label of the given $listType element on the page with the given $pid
* and returns it wrapped for use in the backend preview's header content.
*
* @param int $pid
* @param string $listType
* @return string
*/
protected
function getPluginNameForHeaderContent(int $pid, string $listType): string {
$languageService = GeneralUtility::makeInstance(LanguageService::class);
$pluginName = $languageService->sL(
BackendUtility::getLabelFromItemListMerged(
$pid, 'tt_content', 'list_type', $listType
)
);
return '<span class="label label-info">' . $pluginName . '</span>&nbsp;';
}
/**
* Takes a comma-separated list of record IDs and the corresponding table.
* Returns another comma-space-separated list of the same records with the record titles added.
* The returned list looks nice enough to be rendered in the backend preview directly.
*
* @param $table
* @param $recordIdList
* @return string
*/
protected function addTitlesToRecordIdList(string $table, string $recordIdList): string {
$backendUtility = GeneralUtility::makeInstance(BackendUtility::class);
// Filtering because explode returns [0 => ''] if $recordIdList is empty (i.e. '')
// but we want an empty array in that case.
$recordIdsArray = array_filter(explode(',', $recordIdList));
$recordsWithTitlesArray = [];
foreach ($recordIdsArray as $recordId) {
$recordsWithTitlesArray[] = $backendUtility::getRecord(
$table, $recordId, 'title'
)['title'] . ' [' . $recordId . ']';
}
return implode(', ', $recordsWithTitlesArray);
}
}
<?xml version="1.0" encoding="utf-8" standalone="yes" ?> <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0"> <xliff version="1.0">
<file source-language="en" target-language="de" datatype="plaintext" original="messages" date="2014-03-18T12:47:57Z"> <file source-language="en" target-language="de" datatype="plaintext" original="messages" date="2020-07-17T14:09:42Z">
<header> <header>
<type>module</type> <type>module</type>
<description>Language labels for the backend module belonging to extension 'sg_news'</description> <description>Language labels for the backend module belonging to extension 'sg_news'</description>
...@@ -9,74 +9,82 @@ ...@@ -9,74 +9,82 @@
<authorEmail>stefan@sgalinski.de</authorEmail> <authorEmail>stefan@sgalinski.de</authorEmail>
</header> </header>
<body> <body>
<trans-unit id="backend.plugin.preview.settings" approved="yes">
<source><![CDATA[Settings]]></source>
<target><![CDATA[Einstellungen]]></target>
</trans-unit>
<trans-unit id="backend.plugin.preview.values" approved="yes">
<source><![CDATA[Values]]></source>
<target><![CDATA[Werte]]></target>
</trans-unit>
<trans-unit id="coordinatePicker.missingImage" approved="yes"> <trans-unit id="coordinatePicker.missingImage" approved="yes">
<source>Please upload an image first and save the form!</source> <source><![CDATA[Please upload an image first and save the form!]]></source>
<target>Bitte lade zuerst ein Bild hoch und speichere anschließend das Formular!</target> <target><![CDATA[Bitte lade zuerst ein Bild hoch und speichere anschließend das Formular!]]></target>
</trans-unit> </trans-unit>
<trans-unit id="newsFromAuthorPlugin" approved="yes"> <trans-unit id="descriptionLatestPlugin" approved="yes">
<source>[News] News from author</source> <source><![CDATA[Show latest news.]]></source>
<target>[News] News vom Author</target> <target><![CDATA[Zeige die neuesten News.]]></target>
</trans-unit> </trans-unit>
<trans-unit id="pageType.category" approved="yes"> <trans-unit id="descriptionListByCategoryPlugin" approved="yes">
<source>Category</source> <source><![CDATA[List news by category/tag]]></source>
<target>Kategorie</target> <target><![CDATA[Eine Liste der News aus Kategorien/Tags.]]></target>
</trans-unit> </trans-unit>
<trans-unit id="pageType.news" approved="yes"> <trans-unit id="descriptionOverviewPlugin" approved="yes">
<source>News</source> <source><![CDATA[Show an overview of all news.]]></source>
<target>News</target> <target><![CDATA[Übersicht der News.]]></target>
</trans-unit> </trans-unit>
<trans-unit id="titleLatestPlugin" approved="yes"> <trans-unit id="descriptionSingleViewPlugin" approved="yes">
<source>Latest News</source> <source><![CDATA[Show a single view of news.]]></source>
<target>Neueste News</target> <target><![CDATA[Zeige eine Einzelansicht der News.]]></target>
</trans-unit> </trans-unit>
<trans-unit id="titleListByCategoryPlugin" approved="yes"> <trans-unit id="newsFromAuthorPlugin" approved="yes">
<source>List News by Category/Tag.</source> <source><![CDATA[[News] News from author]]></source>
<target>Liste News aus Kategorien/Tags</target> <target><![CDATA[[News] News vom Author]]></target>
</trans-unit> </trans-unit>
<trans-unit id="titleNewsByAuthorPlugin" approved="yes"> <trans-unit id="pageType.category" approved="yes">
<source>List News by Author.</source> <source><![CDATA[Category]]></source>
<target>Liste News vom Author</target> <target><![CDATA[Kategorie]]></target>
</trans-unit> </trans-unit>
<trans-unit id="titleOverviewPlugin" approved="yes"> <trans-unit id="pageType.news" approved="yes">
<source>News Overview</source> <source><![CDATA[News]]></source>
<target>News Übersicht</target> <target><![CDATA[News]]></target>
</trans-unit> </trans-unit>
<trans-unit id="titleSingleViewPlugin" approved="yes"> <trans-unit id="pageTypeTitlePluginCategory.news" approved="yes">
<source>News Single View</source> <source><![CDATA[[News] News by Category]]></source>
<target>News Einzelansicht</target> <target><![CDATA[[News] News aus Kategorien]]></target>
</trans-unit> </trans-unit>
<trans-unit id="descriptionLatestPlugin"> <trans-unit id="pageTypeTitlePluginLatest.news" approved="yes">
<source>Show latest news.</source> <source><![CDATA[[News] News Latest]]></source>
<target>Zeige die neuesten News.</target> <target><![CDATA[[News] Neueste News]]></target>
</trans-unit> </trans-unit>
<trans-unit id="descriptionListByCategoryPlugin"> <trans-unit id="pageTypeTitlePluginOverview.news" approved="yes">
<source>List news by category/tag.</source> <source><![CDATA[[News] News Overview]]></source>
<target>Eine Liste der News aus Kategorien/Tags.</target> <target><![CDATA[[News] News Übersicht]]></target>
</trans-unit> </trans-unit>
<trans-unit id="descriptionOverviewPlugin"> <trans-unit id="pageTypeTitlePluginSingle.news" approved="yes">
<source>Show an overview of all news.</source> <source><![CDATA[[News] News Single View]]></source>
<target>Übersicht der News.</target> <target><![CDATA[[News] News Einzelansicht]]></target>
</trans-unit> </trans-unit>
<trans-unit id="descriptionSingleViewPlugin"> <trans-unit id="titleLatestPlugin" approved="yes">
<source>Show a single view of news.</source> <source><![CDATA[Latest News]]></source>
<target>Zeige eine Einzelansicht der News.</target> <target><![CDATA[Neueste News]]></target>
</trans-unit> </trans-unit>
<trans-unit id="pageTypeTitlePluginOverview.news"> <trans-unit id="titleListByCategoryPlugin" approved="yes">
<source>[News] News Overview</source> <source><![CDATA[News by Category/Tag]]></source>
<target>[News] News Übersicht</target> <target><![CDATA[Liste News aus Kategorien/Tags]]></target>
</trans-unit> </trans-unit>
<trans-unit id="pageTypeTitlePluginLatest.news"> <trans-unit id="titleNewsByAuthorPlugin" approved="yes">
<source>[News] News Latest</source> <source><![CDATA[List News by Author.]]></source>
<target>[News] Neueste News</target> <target><![CDATA[Liste News vom Author]]></target>
</trans-unit> </trans-unit>
<trans-unit id="pageTypeTitlePluginCategory.news"> <trans-unit id="titleOverviewPlugin" approved="yes">
<source>[News] News by Category</source> <source><![CDATA[News Overview]]></source>
<target>[News] News aus Kategorien</target> <target><![CDATA[News Übersicht]]></target>
</trans-unit> </trans-unit>
<trans-unit id="pageTypeTitlePluginSingle.news"> <trans-unit id="titleSingleViewPlugin" approved="yes">
<source>[News] News Single View</source> <source><![CDATA[News Single View]]></source>
<target>[News] News Einzelansicht</target> <target><![CDATA[News Einzelansicht]]></target>
</trans-unit> </trans-unit>
</body> </body>
</file> </file>
</xliff> </xliff>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" standalone="yes" ?> <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0"> <xliff version="1.0">
<file source-language="en" datatype="plaintext" original="messages" date="2014-03-18T12:47:57Z"> <file source-language="en" datatype="plaintext" original="messages" date="2020-07-17T14:09:42Z">
<header> <header>
<type>module</type> <type>module</type>
<description>Language labels for the backend module belonging to extension 'sg_news'</description> <description>Language labels for the backend module belonging to extension 'sg_news'</description>
...@@ -9,63 +9,69 @@ ...@@ -9,63 +9,69 @@
<authorEmail>stefan@sgalinski.de</authorEmail> <authorEmail>stefan@sgalinski.de</authorEmail>
</header> </header>
<body> <body>
<trans-unit id="backend.plugin.preview.settings">
<source><![CDATA[Settings]]></source>
</trans-unit>
<trans-unit id="backend.plugin.preview.values">
<source><![CDATA[Values]]></source>
</trans-unit>
<trans-unit id="coordinatePicker.missingImage"> <trans-unit id="coordinatePicker.missingImage">
<source>Please upload an image first and save the form!</source> <source><![CDATA[Please upload an image first and save the form!]]></source>
</trans-unit> </trans-unit>
<trans-unit id="newsFromAuthorPlugin"> <trans-unit id="descriptionLatestPlugin">
<source>[News] News from author</source> <source><![CDATA[Show latest news.]]></source>
</trans-unit> </trans-unit>
<trans-unit id="pageTypeTitlePlugin.news"> <trans-unit id="descriptionListByCategoryPlugin">
<source>[News] Plugins</source> <source><![CDATA[List news by category/tag]]></source>
</trans-unit> </trans-unit>
<trans-unit id="pageTypeTitlePluginOverview.news"> <trans-unit id="descriptionOverviewPlugin">
<source>[News] News Overview</source> <source><![CDATA[Show an overview of all news.]]></source>
</trans-unit> </trans-unit>
<trans-unit id="pageTypeTitlePluginLatest.news"> <trans-unit id="descriptionSingleViewPlugin">
<source>[News] News Latest</source> <source><![CDATA[Show a single view of news.]]></source>
</trans-unit> </trans-unit>
<trans-unit id="pageTypeTitlePluginCategory.news"> <trans-unit id="newsFromAuthorPlugin">
<source>[News] News by Category</source> <source><![CDATA[[News] News from author]]></source>
</trans-unit> </trans-unit>
<trans-unit id="pageTypeTitlePluginSingle.news"> <trans-unit id="pageTitlePlugin.news">
<source>[News] News Single View</source> <source><![CDATA[News]]></source>
</trans-unit> </trans-unit>
<trans-unit id="pageType.category"> <trans-unit id="pageType.category">
<source>Category</source> <source><![CDATA[Category]]></source>
</trans-unit> </trans-unit>
<trans-unit id="pageType.news"> <trans-unit id="pageType.news">
<source>News</source> <source><![CDATA[News]]></source>
</trans-unit> </trans-unit>
<trans-unit id="titleLatestPlugin"> <trans-unit id="pageTypeTitlePlugin.news">
<source>Latest News</source> <source><![CDATA[[News] Plugins]]></source>
</trans-unit> </trans-unit>
<trans-unit id="descriptionLatestPlugin"> <trans-unit id="pageTypeTitlePluginCategory.news">
<source>Show latest news.</source> <source><![CDATA[[News] News by Category]]></source>
</trans-unit> </trans-unit>
<trans-unit id="titleListByCategoryPlugin"> <trans-unit id="pageTypeTitlePluginLatest.news">
<source>News by Category/Tag</source> <source><![CDATA[[News] News Latest]]></source>
</trans-unit> </trans-unit>
<trans-unit id="titleNewsByAuthorPlugin"> <trans-unit id="pageTypeTitlePluginOverview.news">
<source>List News by Author.</source> <source><![CDATA[[News] News Overview]]></source>
</trans-unit> </trans-unit>
<trans-unit id="descriptionListByCategoryPlugin"> <trans-unit id="pageTypeTitlePluginSingle.news">
<source>List news by category/tag</source> <source><![CDATA[[News] News Single View]]></source>
</trans-unit> </trans-unit>
<trans-unit id="titleOverviewPlugin"> <trans-unit id="titleLatestPlugin">
<source>News Overview</source> <source><![CDATA[Latest News]]></source>
</trans-unit> </trans-unit>
<trans-unit id="descriptionOverviewPlugin"> <trans-unit id="titleListByCategoryPlugin">
<source>Show an overview of all news.</source> <source><![CDATA[News by Category/Tag]]></source>
</trans-unit> </trans-unit>
<trans-unit id="titleSingleViewPlugin"> <trans-unit id="titleNewsByAuthorPlugin">
<source>News Single View</source> <source><![CDATA[List News by Author.]]></source>
</trans-unit> </trans-unit>
<trans-unit id="descriptionSingleViewPlugin"> <trans-unit id="titleOverviewPlugin">
<source>Show a single view of news.</source> <source><![CDATA[News Overview]]></source>
</trans-unit> </trans-unit>
<trans-unit id="pageTitlePlugin.news"> <trans-unit id="titleSingleViewPlugin">
<source>News</source> <source><![CDATA[News Single View]]></source>
</trans-unit> </trans-unit>
</body> </body>
</file> </file>
</xliff> </xliff>
\ No newline at end of file
<thead>
<tr>
<th scope="col" style="width: 50%">
<f:translate key="LLL:EXT:sg_news/Resources/Private/Language/locallang_backend.xlf:backend.plugin.preview.settings"/>
</th>
<th scope="col" style="width: 50%">
<f:translate key="LLL:EXT:sg_news/Resources/Private/Language/locallang_backend.xlf:backend.plugin.preview.values"/>
</th>
</tr>
</thead>
{namespace be=TYPO3\CMS\Backend\ViewHelpers}
{namespace core=TYPO3\CMS\Core\ViewHelpers}
<be:link.editRecord table="tt_content" uid="{uid}">
<br/>
<table class="table table-striped table-bordered">
<f:render partial="PluginDataTableHeader"/>
<tbody>
<tr>
<th scope="row">
<f:translate
key="LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.overview.flexForm.groupBy"/>
</th>
<td>
<f:translate
key="LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.overview.flexForm.groupBy.I.{data.groupBy}"/>
</td>
</tr>
<tr>
<th scope="row">
<f:translate
key="LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.overview.flexForm.enableFilter"/>
</th>
<td>
<f:if condition="{data.enableFilter}">
<f:then>
<core:icon alternativeMarkupIdentifier="inline" identifier="actions-check"/>
</f:then>
<f:else>
<core:icon alternativeMarkupIdentifier="inline" identifier="actions-close"/>
</f:else>
</f:if>
</td>
</tr>
<tr>
<th scope="row">
<f:translate
key="LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.overview.flexForm.newsLimit"/>
</th>
<td>
{data.newsLimit}
</td>
</tr>
<tr>
<th scope="row">
<f:translate
key="LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.overview.flexForm.onlyNewsWithinThisPageSection"/>
</th>
<td>
<f:if condition="{data.onlyNewsWithinThisPageSection}">
<f:then>
<core:icon alternativeMarkupIdentifier="inline" identifier="actions-check"/>
</f:then>
<f:else>
<core:icon alternativeMarkupIdentifier="inline" identifier="actions-close"/>
</f:else>
</f:if>
</td>
</tr>
<f:if condition="{data.starttime}">
<tr>
<th scope="row">
<f:translate
key="LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.flexForm.starttime"/>
</th>
<td>
<f:format.date format="d.m.Y">{data.starttime}</f:format.date>
</td>
</tr>
</f:if>
<f:if condition="{data.endtime}">
<tr>
<th scope="row">
<f:translate
key="LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.flexForm.endtime"/>
</th>
<td>
<f:format.date format="d.m.Y">{data.endtime}</f:format.date>
</td>
</tr>
</f:if>
<tr>
<th scope="row">
<f:translate
key="LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.flexForm.sortBy"/>
</th>
<td>
<f:switch expression="{data.sortBy}">
<f:case value="typoscript">
<f:translate key="LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.flexForm.systemDefault"/>
</f:case>
<f:case value="date">
<f:translate key="LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.flexForm.dateOfPublication"/>
</f:case>
<f:case value="positionInTree">
<f:translate key="LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.flexForm.orderInPageTree"/>
</f:case>
</f:switch>
</td>
</tr>
<tr>
<th scope="row">
<f:translate
key="LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.flexForm.sortOrder"/>
</th>
<td>
<f:switch expression="{data.sortDirection}">
<f:case value="typoscript">
<f:translate key="LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.flexForm.systemDefault"/>
</f:case>
<f:case value="DESC">
<f:translate key="LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.flexForm.desc"/>
</f:case>
<f:case value="ASC">
<f:translate key="LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.flexForm.asc"/>
</f:case>
</f:switch>
</td>
</tr>
</tbody>
</table>
</be:link.editRecord>
...@@ -99,6 +99,8 @@ call_user_func( ...@@ -99,6 +99,8 @@ call_user_func(
// hook registration // hook registration
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] =
'SGalinski\SgNews\TCA\TcaProvider'; 'SGalinski\SgNews\TCA\TcaProvider';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem']['sg_news']
= \SGalinski\SgNews\Hooks\PageLayoutView\PluginRenderer::class;
// Xclasses // Xclasses
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['TYPO3\CMS\Core\Page\PageRenderer'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['TYPO3\CMS\Core\Page\PageRenderer'] =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment