Commit 6c62dedb authored by Matthias Adrowski's avatar Matthias Adrowski
Browse files

[TASK] Migrate Backendpreview, fix autowiring issues

parent 06373031
......@@ -93,7 +93,7 @@ class PluginController extends AbstractPlugin {
if ($this->pluginConfiguration['renderer'] === 'TypoScript' || !$this->pluginConfiguration['renderer']) {
/** @var $renderer TypoScriptView */
$renderer = GeneralUtility::makeInstance(TypoScriptView::class);
$renderer->injectPluginConfiguration($this->pluginConfiguration, $tabId);
$renderer->addPluginConfiguration($this->pluginConfiguration, $tabId);
$renderer->injectPageRenderer(GeneralUtility::makeInstance(PageRenderer::class));
$renderer->injectContentObject($this->cObj);
$repository = $this->getTabRepository();
......
......@@ -52,7 +52,7 @@ abstract class AbstractBaseDataProvider implements InterfaceDataProvider, Single
* @param array $configuration
* @return void
*/
public function injectPluginConfiguration(array $configuration) {
public function addPluginConfiguration(array $configuration) {
$this->pluginConfiguration = $configuration;
}
......
......@@ -56,7 +56,7 @@ final class FactoryDataProvider {
}
/** @var $dataProvider AbstractBaseDataProvider */
$dataProvider->injectPluginConfiguration($pluginConfiguration);
$dataProvider->addPluginConfiguration($pluginConfiguration);
$dataProvider->injectContentObject($contentObject);
return $dataProvider;
......
<?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\DfTabs\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 $item
* @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>&nbsp;</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:df_tabs/Resources/Private/Partials/Backend']);
$view->setTemplateRootPaths(['EXT:df_tabs/Resources/Private/Templates/Backend']);
$view->setTemplate('Tabs.html');
$view->assign('uid', $item->getRecord()['uid']);
// Get available plugin settings and their values from flexform
$templateData = [];
// Get available plugin settings and their values from flexform
$pluginConfiguration = GeneralUtility::xml2array(
$item->getRecord()['pi_flexform'],
'T3DataStructure'
)['data']['sDEF']['lDEF'];
$tabElements = GeneralUtility::trimExplode(',', $pluginConfiguration['data']['vDEF'], TRUE);
$tabs = [];
foreach ($tabElements as $tabElement) {
// Each $tabElement is either 'pages_<id>' or 'tt_content_<id>'.
$recordTable = substr($tabElement, 0, strrpos($tabElement, '_'));
$recordId = substr($tabElement, strrpos($tabElement, '_') + 1);
if ($recordTable === 'pages') {
$recordTitle = BackendUtility::getRecord($recordTable, $recordId, 'title')['title'];
$recordType = 'page';
} elseif ($recordTable === 'tt_content') {
$recordTitle = BackendUtility::getRecord($recordTable, $recordId, 'header')['header'];
$recordType = 'content';
} else {
$recordTitle = $tabElement;
$recordType = 'unknown';
}
$tabs[] = [
'type' => $recordType,
'title' => $recordTitle,
'uid' => $recordId
];
}
$titles = GeneralUtility::trimExplode("\n", $pluginConfiguration['titles']['vDEF']);
// Remove first item if it is empty to mimic what is actually saved to the DB and frontend behaviour.
// This gets done automatically on a second save of the plugin anyways but it should happen every time.
if ($titles[0] === '') {
array_shift($titles);
}
$templateData = [
'mode' => $pluginConfiguration['mode']['vDEF'],
'tabs' => $tabs,
'titles' => $titles,
'enableAutoPlay' => $pluginConfiguration['enableAutoPlay']['vDEF'],
'autoPlayInterval' => $pluginConfiguration['autoPlayInterval']['vDEF'],
'enableMouseOver' => $pluginConfiguration['enableMouseOver']['vDEF'],
'hashName' => $pluginConfiguration['hashName']['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 . $previewContent;
}
}
......@@ -76,7 +76,7 @@ class TypoScriptView implements SingletonInterface {
* @param string $tabId
* @return void
*/
public function injectPluginConfiguration(array $configuration, $tabId) {
public function addPluginConfiguration(array $configuration, $tabId) {
$this->pluginConfiguration[$tabId] = $configuration;
$this->pluginConfiguration[$tabId]['counter'] = $this->counter;
......@@ -94,7 +94,7 @@ class TypoScriptView implements SingletonInterface {
* @param PageRenderer $pageRenderer
* @return void
*/
public function injectPageRenderer($pageRenderer) {
public function injectPageRenderer(PageRenderer $pageRenderer) {
$this->pageRenderer = $pageRenderer;
}
......@@ -104,7 +104,7 @@ class TypoScriptView implements SingletonInterface {
* @param ContentObjectRenderer $contentObject
* @return void
*/
public function injectContentObject($contentObject) {
public function injectContentObject(ContentObjectRenderer $contentObject) {
$this->contentObject = $contentObject;
}
......
services:
_defaults:
autowire: true
autoconfigure: true
public: false
SGalinski\DfTabs\:
resource: '../Classes/*'
SGalinski\DfTabs\Preview\PreviewRenderer:
public: true
......@@ -58,5 +58,7 @@ call_user_func(
\TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider::class,
['source' => 'EXT:df_tabs/Resources/Public/Images/contentElementWizard.png']
);
$GLOBALS['TCA']['tt_content']['types']['list']['previewRenderer']['df_tabs_plugin1'] = \SGalinski\DfTabs\Preview\PreviewRenderer::class;
}
);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment