Skip to content
Snippets Groups Projects
Verified Commit 75c35f7e authored by Kevin Ditscheid's avatar Kevin Ditscheid
Browse files

[TASK] Implement Fluid Based Page Module approach of rendering the backend preview

parent 6f8e5149
No related branches found
No related tags found
1 merge request!6TYPO3 11
......@@ -32,6 +32,7 @@ use \TYPO3\CMS\Core\Localization\LanguageService;
* Renders back-end preview for the SG YouTube Videos plugin
*
* @package SGalinski\SgYoutube\Hooks
* @deprecated All of this class will be removed when TYPO3 10 support is dropped
*/
class PluginRenderer implements PageLayoutViewDrawItemHookInterface {
/**
......@@ -44,10 +45,16 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface {
* @param array $row Record row of tt_content
* @return void
* @noinspection ReferencingObjectsInspection
* @deprecated All of this class will be removed when TYPO3 10 support is dropped
*/
public function preProcess(
PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row
): void {
trigger_error(
'Using the old style of rendering backend previews is deprecated and will not longer work when TYPO3 10'
. ' support is dropped! Please switch to using the Fluid Based Page Module instead!',
E_DEPRECATED
);
if ($row['list_type'] === 'sgyoutube_youtube') {
$drawItem = FALSE;
......
<?php
/***************************************************************
* 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!
***************************************************************/
namespace SGalinski\SgYoutube\Preview;
use TYPO3\CMS\Backend\Preview\PreviewRendererInterface;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
class PreviewRenderer implements PreviewRendererInterface {
/**
* @var LanguageService $languageService
*/
protected LanguageService $languageService;
public function __construct(LanguageService $languageService)
{
$this->languageService = $languageService;
}
/**
* Dedicated method for rendering preview header HTML for
* the page module only. Receives $item which is an instance of
* GridColumnItem which has a getter method to return the record.
*
* @param GridColumnItem
* @return string
*/
public function renderPageModulePreviewHeader(GridColumnItem $item): string {
$label = BackendUtility::getLabelFromItemListMerged(
$item->getRecord()['pid'], 'tt_content', 'list_type', $item->getRecord()['list_type']
);
return '<h4><span class="label label-primary">' . $this->languageService->sL($label) . '</span></h4>';
}
/**
* Dedicated method for rendering preview body HTML for
* the page module only.
*
* @param GridColumnItem $item
* @return string
*/
public function renderPageModulePreviewContent(GridColumnItem $item): string {
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setPartialRootPaths(['EXT:sg_youtube/Resources/Private/Partials/Backend']);
$view->setTemplateRootPaths(['EXT:sg_youtube/Resources/Private/Templates/Youtube']);
$view->setTemplate('Backend.html');
$view->assign('uid', $item->getRecord()['uid']);
// Get available plugin settings and their values from flexform
$pluginConfiguration = GeneralUtility::xml2array(
$item->getRecord()['pi_flexform'], 'T3DataStructure'
)['data']['sDEF']['lDEF'];
$templateData = [
'youtubeId' => $pluginConfiguration['settings.id']['vDEF'],
'maxResults' => $pluginConfiguration['settings.maxResults']['vDEF'],
'showTitle' => (int) ($pluginConfiguration['settings.showTitle']['vDEF'] ?? 1),
'showDescription' => (int) ($pluginConfiguration['settings.showDescription']['vDEF'] ?? 1),
'disableLightbox' => $pluginConfiguration['settings.disableLightbox']['vDEF'],
'disableLightboxMobile' => $pluginConfiguration['settings.disableLightboxMobile']['vDEF'],
'aspectRatio' => $pluginConfiguration['settings.aspectRatio']['vDEF'],
'thumbnailType' => $pluginConfiguration['settings.thumbnailType']['vDEF'],
'thumbnailImagesCount' => $pluginConfiguration['settings.thumbnailImages']['vDEF'],
'showApiResult' => $pluginConfiguration['settings.showApiResult']['vDEF'],
];
$view->assign('data', $templateData);
return $view->render();
}
/**
* Render a footer for the record to display in page module below
* the body of the item's preview.
*
* @param GridColumnItem $item
* @return string
*/
public function renderPageModulePreviewFooter(GridColumnItem $item): string {
return '';
}
/**
* Dedicated method for wrapping a preview header and body HTML.
*
* @param string $previewHeader
* @param string $previewContent
* @param GridColumnItem $item
* @return string
*/
public function wrapPageModulePreview(string $previewHeader, string $previewContent, GridColumnItem $item): string {
return $previewHeader . '<br>' . $previewContent;
}
}
\ No newline at end of file
services:
_defaults:
autowire: true
autoconfigure: true
public: false
SGalinski\SgYoutube\:
resource: '../Classes/*'
SGalinski\SgYoutube\Preview\PreviewRenderer:
public: true
\ No newline at end of file
......@@ -10,3 +10,7 @@ $GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist']['sgyoutube_yo
'Youtube',
'YouTube Videos'
);
// add the backend preview for the youtube plugin
$GLOBALS['TCA']['tt_content']['types']['list']['previewRenderer']['sgyoutube_youtube'] =
\SGalinski\SgYoutube\Preview\PreviewRenderer::class;
\ No newline at end of file
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