<?php namespace SGalinski\SgVimeo\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 SGalinski\SgComments\Domain\Model\Language; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Backend\View\PageLayoutView; use TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Fluid\View\StandaloneView; use \TYPO3\CMS\Core\Localization\LanguageService; /** * Class PluginRenderer * Renders back-end preview for the SG Vimeo Videos plugin * * @package SGalinski\SgVimeo\Hooks */ class PluginRenderer implements PageLayoutViewDrawItemHookInterface { /** * Preprocesses the preview rendering of a content element of type "sg_vimeo" * * @param PageLayoutView $parentObject Calling parent object * @param bool $drawItem Whether to draw the item using the default functionality * @param string $headerContent Header content * @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 ): void { if ($row['list_type'] === 'sgvimeo_vimeo') { $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); $itemContent .= $view->render(); } } /** * 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 { /** @var LanguageService $languageService */ $languageService = GeneralUtility::makeInstance(LanguageService::class); $pluginName = $languageService->sL( BackendUtility::getLabelFromItemListMerged( $pid, 'tt_content', 'list_type', $listType ) ); return '<span class="label label-primary">' . $pluginName . '</span> '; } }