Skip to content
Snippets Groups Projects
PreviewService.php 3.51 KiB
Newer Older
<?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\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;

/**
 * PreviewService, to get Views while we have to duplicate previewCode
 */
Stefan Galinski's avatar
Stefan Galinski committed
class PreviewService {
	public const RETURNTYPE_ARR = 'array';
Stefan Galinski's avatar
Stefan Galinski committed
	/**
	 * returns the usable PluginView
	 *
	 * @param array $row
	 * @return StandaloneView
	 */
	public function getPluginPreview(array $row): StandaloneView {
		$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', $row['uid']);
Stefan Galinski's avatar
Stefan Galinski committed
		// Get available plugin settings and their values from flexform
		$pluginConfiguration = GeneralUtility::xml2array(
			$row['pi_flexform'],
			'T3DataStructure'
		)['data']['sDEF']['lDEF'];
Stefan Galinski's avatar
Stefan Galinski committed
		$templateData = [
			'youtubeId' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.id'),
			'maxResults' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.maxResults'),
Stefan Galinski's avatar
Stefan Galinski committed
			'showTitle' => (int) ($this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.showTitle') ?? 1),
			'showDescription' => (int) ($this->passVDefOnKeyToTemplate(
				$pluginConfiguration,
				'settings.showDescription'
Stefan Galinski's avatar
Stefan Galinski committed
			) ?? 1),
Stefan Galinski's avatar
Stefan Galinski committed
			'disableLightbox' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.disableLightbox'),
Stefan Galinski's avatar
Stefan Galinski committed
			'disableLightboxMobile' => $this->passVDefOnKeyToTemplate(
				$pluginConfiguration,
				'settings.disableLightboxMobile'
Stefan Galinski's avatar
Stefan Galinski committed
			),
Stefan Galinski's avatar
Stefan Galinski committed
			'aspectRatio' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.aspectRatio'),
			'thumbnailType' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.thumbnailType'),
			'thumbnailImagesCount' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.thumbnailImages'),
			'showApiResult' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.showApiResult'),
			'urlParameters' => $this->passVDefOnKeyToTemplate($pluginConfiguration, 'settings.urlParameters'),
Georgi's avatar
Georgi committed
			'header' => $row['header'],
Stefan Galinski's avatar
Stefan Galinski committed
		];
Stefan Galinski's avatar
Stefan Galinski committed
		$view->assign('data', $templateData);
		return $view;
	}
Stefan Galinski's avatar
Stefan Galinski committed
	/**
	 * @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'];
		}
Stefan Galinski's avatar
Stefan Galinski committed
		// check if we got a possible returntype:
		if ($returnType === self::RETURNTYPE_ARR) {
			return [];
		}
Stefan Galinski's avatar
Stefan Galinski committed
		return '';
	}