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

[TASK] Render plugin backend preview with Fluid template

parent 72479e3c
No related branches found
No related tags found
1 merge request!1[FEATURE] Add backend preview for the YouTube Videos plugin
<?php
namespace SGalinski\SgYoutube\Hooks;
namespace SGalinski\SgYoutube\Hooks\PageLayoutView;
/***************************************************************
* Copyright notice
......@@ -23,10 +23,9 @@ namespace SGalinski\SgYoutube\Hooks;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Form\Service\TranslationService;
use TYPO3\CMS\Fluid\View\StandaloneView;
use \TYPO3\CMS\Core\Localization\LanguageService;
/**
* Class PluginRenderer
......@@ -47,7 +46,7 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface {
$records = [];
foreach ($recordsArray as $i => $recordId) {
$records[] = $backendUtilityObject->getRecord(
$records[] = $backendUtilityObject::getRecord(
$table, $recordId, 'title'
)['title'] . ' ' . '(' . $recordId . ')';
}
......@@ -63,125 +62,47 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface {
* @param string $itemContent Item content
* @param array $row Record row of tt_content
* @return void
* @noinspection ReferencingObjectsInspection
*/
public function preProcess(PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row) {
public function preProcess(
PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row
): void {
if ($row['list_type'] === 'sgyoutube_youtube') {
$drawItem = FALSE;
// Content element labels
$labelPluginName = BackendUtility::getLabelFromItemListMerged(
$row['pid'], 'tt_content', 'list_type', $row['list_type']
);
$labelSubheader = BackendUtility::getItemLabel(
'tt_content', 'subheader'
);
// Instantiate TranslationService class
$translationServiceObject = GeneralUtility::makeInstance(TranslationService::class);
// Begin rendering of content element fields
// Plugin name
$headerContent = '<div style="padding: 0 4px 10px 0;border-bottom: 1px solid #CACACA;margin-bottom: 6px; font-weight:700;">' . $labelPluginName . '</div>';
// Header
if ($row['header']) {
if ($row['header_layout'] === '10') {
$headerContent .= '<p>' . $row['header'] . '</p>';
} elseif ($row['header_layout'] === '100') {
$headerContent .= '<div style="display:none;">' . $row['header'] . '</div>';
} else {
$headerContent .= '<h' . $row['header_layout'] . '>' . $row['header'] . '</h' . $row['header_layout'] . '>';
}
}
// Subheader
if ($row['subheader']) {
$headerContent .= '<div>' . '<strong>' . $translationServiceObject->translate(
$labelSubheader
) . '</strong>' . ':&nbsp;' . $row['subheader'] . '</div>';
}
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplateRootPaths(['EXT:sg_youtube/Resources/Private/Templates/Youtube']);
$view->setTemplate('Backend.html');
$view->assign('uid', $row['uid']);
// Set plugin options array
$pluginOptions = GeneralUtility::xml2array($row['pi_flexform'], 'T3:');
// Get the FlexForm configuration file
$xmlFilePath = $GLOBALS['TCA']['tt_content']['columns']['pi_flexform']['config']['ds']['sgyoutube_youtube,list'];
if ($xmlFilePath !== '') {
$xmlContent = GeneralUtility::getFileAbsFileName(
str_replace(
'FILE:EXT:', 'EXT:', $xmlFilePath
)
);
// Get contents of the FlexForm configuration file
$xmlString = file_get_contents($xmlContent);
$configurationArray = GeneralUtility::xml2array($xmlString);
// Begin rendering of table
$itemContent .= '<br>' . '<table class="table table-striped">';
// Table header
$labelSettings = 'LLL:EXT:sg_youtube/Resources/Private/Language/locallang.xlf:settings';
$labelvalue = 'LLL:EXT:sg_youtube/Resources/Private/Language/locallang.xlf:values';
$itemContent .= '<row>' . '<th style="width: 50%">' . $translationServiceObject->translate(
$labelSettings
) . '</th>';
$itemContent .= '<th style="width: 50%">' . $translationServiceObject->translate(
$labelvalue
) . '</th>' . '</tr>';
// Loop through plugin options and render rows
foreach ($pluginOptions['data']['sDEF']['lDEF'] as $key => $setting) {
// if plugin option exists within the Flexform configuration file
if (array_key_exists($key, $configurationArray['sheets']['sDEF']['ROOT']['el'])) {
// Display label
$labelId = $configurationArray['sheets']['sDEF']['ROOT']['el'][$key]['TCEforms']['label'];
$itemContent .= '<row>' . '<td><strong>' . $translationServiceObject->translate(
trim($labelId)
) . '</strong></td>';
// Display value
// Show different icon for the 'Show API Result' field, depending on checkbox value
if ($key === 'settings.showApiResult') {
if ($setting['vDEF'] === '0') {
$itemContent .= '<td>' . GeneralUtility::makeInstance(IconFactory::class)->getIcon(
'actions-close', Icon::SIZE_SMALL
)
->render('inline') . '</td>' . '</tr>';
} else {
$itemContent .= '<td>' . GeneralUtility::makeInstance(IconFactory::class)->getIcon(
'actions-check', Icon::SIZE_SMALL
)
->render('inline') . '</td>' . '</tr>';
}
// Remaining values
} else {
$itemContent .= '<td>' . $setting['vDEF'] . '</td>' . '</tr>';
}
}
$templateOptions = [];
foreach ($pluginOptions['data']['sDEF']['lDEF'] as $option => $value) {
if ($option !== 'settings.showApiResult') {
// $option has the format 'settings.<key>', but in the template we need the language label which
// has the format 'flexform.<key>'.
$templateOptions[str_replace('settings.', 'flexform.', $option)] = $value['vDEF'];
}
}
// Record Storage
if ($row['pages'] !== '') {
// Record Storage Page label
$labelRecordStorage = 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:pages.ALT.list_formlabel';
$languageService = GeneralUtility::makeInstance(LanguageService::class);
$templateOptions['flexform.thumbnailType'] = $languageService->sL(
'LLL:EXT:sg_youtube/Resources/Private/Language/locallang.xlf:flexform.thumbnailType.' . $templateOptions['flexform.thumbnailType']
);
// Render 'Record Storage Page' row
$itemContent .= '<row>' . '<td><strong>' . $translationServiceObject->translate(
$labelRecordStorage
) . '</strong></td>';
$itemContent .= '<td>' . implode(
', ', $this->buildRecordArray('pages', $row['pages'])
) . '</td>' . '</tr>';
}
$view->assignMultiple([
'pluginOptions' => $templateOptions,
'showApiResult' => $pluginOptions['data']['sDEF']['lDEF']['settings.showApiResult']['vDEF']
]);
// End rendering of table
$itemContent .= '</table>';
}
// Content element labels
$pluginName = BackendUtility::getLabelFromItemListMerged(
$row['pid'], 'tt_content', 'list_type', $row['list_type']
);
$headerContent = '<strong>[' . $pluginName . '] </strong>' . $headerContent;
$itemContent .= $view->render();
}
}
}
......@@ -16,7 +16,7 @@
<settings.id>
<TCEforms>
<exclude>0</exclude>
<label>LLL:EXT:sg_youtube/Resources/Private/Language/locallang.xlf:id
<label>LLL:EXT:sg_youtube/Resources/Private/Language/locallang.xlf:flexform.id
</label>
<config>
<type>input</type>
......@@ -28,7 +28,7 @@
<settings.maxResults>
<TCEforms>
<exclude>0</exclude>
<label>LLL:EXT:sg_youtube/Resources/Private/Language/locallang.xlf:maxResults
<label>LLL:EXT:sg_youtube/Resources/Private/Language/locallang.xlf:flexform.maxResults
</label>
<config>
<type>input</type>
......
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" target-language="de" datatype="plaintext" original="messages" date="2020-06-10T09:14:47Z">
<file source-language="en" target-language="de" datatype="plaintext" original="messages" date="2020-06-24T18:20:58Z">
<header>
<generator>LFEditor</generator>
</header>
<body>
<trans-unit id="backendPreview.apiDebugWarning.header" approved="yes">
<source><![CDATA[API Debugging Information is Shown in the Frontend]]></source>
<target><![CDATA[API-Debugging-Details werden im Frontend gerendert]]></target>
</trans-unit>
<trans-unit id="backendPreview.apiDebugWarning.message" approved="yes">
<source><![CDATA[Uncheck the debugging option in the plugin options to not show this information.]]></source>
<target><![CDATA[Deaktivieren Sie die Debugging-Option in den Plugin-Einstellungen, um diese Informationen nicht anzuzeigen.]]></target>
</trans-unit>
<trans-unit id="backendPreview.settings" approved="yes">
<source><![CDATA[Settings]]></source>
<target><![CDATA[Einstellungen]]></target>
</trans-unit>
<trans-unit id="backendPreview.values" approved="yes">
<source><![CDATA[Values]]></source>
<target><![CDATA[Werte]]></target>
</trans-unit>
<trans-unit id="flexform.aspectRatio" approved="yes">
<source><![CDATA[Aspect Ratio (only used if thumbnail type is set to check that)]]></source>
<target><![CDATA[Aspect Ratio (nur genutzt, wenn der Thumbnail-Typ dies prüfen soll)]]></target>
</trans-unit>
<trans-unit id="flexform.id" approved="yes">
<source><![CDATA[ID of Channel (UC), Playlist (PL) or Single Video (youtube.com/watch?v=%ID%)]]></source>
<target><![CDATA[ID eines Channels (UC), einer Playlist (PL) oder eines einzelnen Videos (youtube.com/watch?v=%ID%)]]></target>
</trans-unit>
<trans-unit id="flexform.maxResults" approved="yes">
<source><![CDATA[Maximum Amount]]></source>
<target><![CDATA[Maximale Anzahl]]></target>
</trans-unit>
<trans-unit id="flexform.showApiResult" approved="yes">
<source><![CDATA[Show API Result (Debug Output!)]]></source>
<target><![CDATA[Zeige API-Ergebnis an (Debug-Informationen!)]]></target>
......@@ -41,22 +65,6 @@
<source><![CDATA[Standard Resolution]]></source>
<target><![CDATA[Standard-Auflösung]]></target>
</trans-unit>
<trans-unit id="id" approved="yes">
<source><![CDATA[ID of Channel (UC), Playlist (PL) or Single Video (youtube.com/watch?v=%ID%)]]></source>
<target><![CDATA[ID eines Channels (UC), einer Playlist (PL) oder eines einzelnen Videos (youtube.com/watch?v=%ID%)]]></target>
</trans-unit>
<trans-unit id="maxResults" approved="yes">
<source><![CDATA[Maximum Amount]]></source>
<target><![CDATA[Maximale Anzahl]]></target>
</trans-unit>
<trans-unit id="settings" approved="yes">
<source><![CDATA[Settings]]></source>
<target><![CDATA[Einstellungen]]></target>
</trans-unit>
<trans-unit id="values" approved="yes">
<source><![CDATA[Values]]></source>
<target><![CDATA[Werte]]></target>
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" datatype="plaintext" original="messages" date="2019-12-07T19:09:30Z">
<file source-language="en" datatype="plaintext" original="messages" date="2020-06-24T18:20:58Z">
<header>
<generator>LFEditor</generator>
</header>
<body>
<trans-unit id="backendPreview.apiDebugWarning.header">
<source><![CDATA[API Debugging Information is Shown in the Frontend]]></source>
</trans-unit>
<trans-unit id="backendPreview.apiDebugWarning.message">
<source><![CDATA[Uncheck the debugging option in the plugin options to not show this information.]]></source>
</trans-unit>
<trans-unit id="backendPreview.settings">
<source><![CDATA[Settings]]></source>
</trans-unit>
<trans-unit id="backendPreview.values">
<source><![CDATA[Values]]></source>
</trans-unit>
<trans-unit id="flexform.aspectRatio">
<source><![CDATA[Aspect Ratio (only used if thumbnail type is set to check that)]]></source>
</trans-unit>
<trans-unit id="flexform.id">
<source><![CDATA[ID of Channel (UC), Playlist (PL) or Single Video (youtube.com/watch?v=%ID%)]]></source>
</trans-unit>
<trans-unit id="flexform.maxResults">
<source><![CDATA[Maximum Amount]]></source>
</trans-unit>
<trans-unit id="flexform.showApiResult">
<source><![CDATA[Show API Result (Debug Output!)]]></source>
</trans-unit>
......@@ -32,18 +50,6 @@
<trans-unit id="flexform.thumbnailType.standard">
<source><![CDATA[Standard Resolution]]></source>
</trans-unit>
<trans-unit id="id">
<source><![CDATA[ID of Channel (UC), Playlist (PL) or Single Video (youtube.com/watch?v=%ID%)]]></source>
</trans-unit>
<trans-unit id="maxResults">
<source><![CDATA[Maximum Amount]]></source>
</trans-unit>
<trans-unit id="settings">
<source><![CDATA[Settings]]></source>
</trans-unit>
<trans-unit id="values">
<source><![CDATA[Values]]></source>
</trans-unit>
</body>
</file>
</xliff>
</xliff>
\ No newline at end of file
{namespace be=TYPO3\CMS\Backend\ViewHelpers}
<be:link.editRecord uid="{uid}" table="tt_content">
<br/>
<f:if condition="{showApiResult} == 1">
<div class="alert alert-warning">
<h4 class="alert-title"><f:translate key="backendPreview.apiDebugWarning.header" extensionName="sg_youtube"/></h4>
<p class="alert-message"><f:translate key="backendPreview.apiDebugWarning.message" extensionName="sg_youtube"/></p>
</div>
</f:if>
<table class="table table-striped">
<tr>
<th style="width: 50%">
<f:translate key="backendPreview.settings" extensionName="sg_youtube"/>
</th>
<th style="width: 50%">
<f:translate key="backendPreview.values" extensionName="sg_youtube"/>
</th>
</tr>
<f:for each="{pluginOptions}" as="option" key="labelKey">
<tr>
<th>
<f:translate key="{labelKey}" extensionName="sg_youtube"/>
</th>
<td>
{option}
</td>
</tr>
</f:for>
</table>
</be:link.editRecord>
......@@ -42,4 +42,4 @@ if (!defined('TYPO3_MODE')) {
);
//Hooks
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem']['sg_youtube']
= \SGalinski\SgYoutube\Hooks\PluginRenderer::class;
= \SGalinski\SgYoutube\Hooks\PageLayoutView\PluginRenderer::class;
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