Skip to content
Snippets Groups Projects
Commit a0ea8b41 authored by Matthias Adrowski's avatar Matthias Adrowski
Browse files

[TASK] Migrate to PreviewService

parent 0c1f9eee
No related branches found
No related tags found
1 merge request!3Feature upgrade to typo3 11
......@@ -20,6 +20,7 @@ namespace SGalinski\SgVimeo\Hooks\PageLayoutView;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use SGalinski\SgTeaser\Preview\PreviewService;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface;
......@@ -32,9 +33,16 @@ use TYPO3\CMS\Fluid\View\StandaloneView;
* Renders back-end preview for the SG Vimeo Videos plugin
*
* @package SGalinski\SgVimeo\Hooks
* @deprecated All of this class will be removed when TYPO3 10 support is dropped
* @deprecated All of this class will be removed when PageLayoutView support is dropped
*/
class PluginRenderer implements PageLayoutViewDrawItemHookInterface {
protected PreviewService $previewService;
public function init() {
$this->previewService = GeneralUtility::makeInstance(PreviewService::class);
}
/**
* Preprocesses the preview rendering of a content element of type "sg_vimeo"
*
......@@ -54,6 +62,8 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface {
&$itemContent,
array &$row
): void {
$this->init();
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!',
......@@ -63,33 +73,8 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface {
$drawItem = FALSE;
$this->adaptPluginHeaderContent($headerContent, $row);
/** @var StandaloneView $view */
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setPartialRootPaths(['EXT:sg_vimeo/Resources/Private/Partials/Backend']);
$view->setTemplateRootPaths(['EXT:sg_vimeo/Resources/Private/Templates/Vimeo']);
$view->setTemplate('Backend.html');
$view->assign('uid', $row['uid']);
// Get available plugin settings and their values from flexform
$pluginConfiguration = GeneralUtility::xml2array(
$row['pi_flexform'],
'T3DataStructure'
)['data']['sDEF']['lDEF'];
$templateData = [
'vimeoId' => $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);
$view = $this->previewService->getPluginView($row);
$itemContent .= $view->render();
}
......
......@@ -33,8 +33,11 @@ class PreviewRenderer implements PreviewRendererInterface {
*/
protected LanguageService $languageService;
public function __construct(LanguageService $languageService) {
protected PreviewService $previewService;
public function __construct(LanguageService $languageService, PreviewService $previewService) {
$this->languageService = $languageService;
$this->previewService = $previewService;
}
/**
......@@ -63,33 +66,7 @@ class PreviewRenderer implements PreviewRendererInterface {
* @return string
*/
public function renderPageModulePreviewContent(GridColumnItem $item): string {
/** @var StandaloneView $view */
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setPartialRootPaths(['EXT:sg_vimeo/Resources/Private/Partials/Backend']);
$view->setTemplateRootPaths(['EXT:sg_vimeo/Resources/Private/Templates/Vimeo']);
$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 = [
'vimeoId' => $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);
$view = $this->previewService->getPluginView($item->getRecord());
return $view->render();
}
......
<?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\SgVimeo\Preview;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
/**
* PreviewService, to get Views while we have to duplicate previewCode
*/
class PreviewService {
public const RETURNTYPE_ARR = 'array';
public function getPluginView(array $row): StandaloneView {
/** @var StandaloneView $view */
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setPartialRootPaths(['EXT:sg_vimeo/Resources/Private/Partials/Backend']);
$view->setTemplateRootPaths(['EXT:sg_vimeo/Resources/Private/Templates/Vimeo']);
$view->setTemplate('Backend.html');
$view->assign('uid', $row['uid']);
// Get available plugin settings and their values from flexform
$pluginConfiguration = GeneralUtility::xml2array(
$row['pi_flexform'],
'T3DataStructure'
)['data']['sDEF']['lDEF'];
$templateData = [
'vimeoId' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.id'),
'maxResults' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.maxResults'),
'showTitle' => (int) ($this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.showTitle') ?? 1),
'showDescription' => (int) ($this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.showDescription') ?? 1),
'disableLightbox' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.disableLightbox'),
'disableLightboxMobile' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.disableLightboxMobile'),
'aspectRatio' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.aspectRatio'),
'thumbnailType' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.thumbnailType'),
'thumbnailImagesCount' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.thumbnailImages'),
'showApiResult' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.showApiResult'),
];
$view->assign('data', $templateData);
return $view;
}
/**
* @param array $conf
* @param string $key
* @param string $returnType
* @return array|mixed|string
*/
private function passVDefOnKeyToTemplate(array $conf, string $key, string $returnType = '') {
if(isset($conf[$key])) {
return $conf[$key]['vDEF'];
}
// check if we got a possible returntype:
if($returnType === self::RETURNTYPE_ARR) {
return [];
}
return '';
}
}
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