Skip to content
Snippets Groups Projects
Commit 2ef487b2 authored by Ciprian Hossu's avatar Ciprian Hossu
Browse files

[FEATURE] Add backend preview for the YouTube Videos plugin

parent 547bc5ad
No related branches found
No related tags found
1 merge request!1[FEATURE] Add backend preview for the YouTube Videos plugin
<?php
namespace SGalinski\SgYoutube\Hooks;
/***************************************************************
* 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 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\Form\Service\TranslationService;
/**
* Class PluginRenderer
* Renders back-end preview for the SG YouTube Videos plugin
*
* @package SGalinski\SgYoutube\Hooks
*/
class PluginRenderer implements PageLayoutViewDrawItemHookInterface {
/**
* Preprocesses the preview rendering of a content element of type "sg_youtube"
*
* @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
*/
public function preProcess(PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row) {
if ($row['list_type'] === 'sgyoutube_youtube') {
// Content element labels
$labelPluginName = BackendUtility::getLabelFromItemListMerged(
$row['pid'], 'tt_content', 'list_type', $row['list_type']
);
$labelHeader = BackendUtility::getItemLabel(
'tt_content', 'header'
);
$labelHeaderLink = BackendUtility::getItemLabel(
'tt_content', 'header_link'
);
$labelSubheader = BackendUtility::getItemLabel(
'tt_content', 'subheader'
);
$labelContentLink = BackendUtility::getItemLabel(
'tt_content', 'tx_sgcontentlink_contentlink'
);
// Make instance of TranslationService class
$translationServiceObject = GeneralUtility::makeInstance(TranslationService::class);
// Begin rendering of content element fields
// Plugin name
$headerContent = '<div style="padding: 0 4px 10px 0;border-bottom: 1px solid #CACACA;margin-bottom: 6px; font-weight:700;">' . $labelPluginName . '</div>';
// Header
if ($row['header']) {
if ($row['header_layout'] === '10') {
$headerContent .= '<p>' . $row['header'] . '</p>';
} elseif ($row['header_layout'] === '100') {
$headerContent .= '<div style="display:none;">' . $row['header'] . '</div>';
} else {
$headerContent .= '<h' . $row['header_layout'] . '>' . $row['header'] . '</h' . $row['header_layout'] . '>';
}
}
//Header link
if ($row['header_link']) {
$headerContent .= '<div><strong>' . $translationServiceObject->translate(
$labelHeaderLink
) . '&nbsp;(' . $translationServiceObject->translate(
$labelHeader
) . ')</strong>:&nbsp;' . $row['header_link'] . '</div>';
}
// Subheader
if ($row['subheader']) {
$headerContent .= '<div>' . '<strong>' . $translationServiceObject->translate(
$labelSubheader
) . '</strong>' . ':&nbsp;' . $row['subheader'] . '</div>';
}
// Content link
if ($row['tx_sgcontentlink_contentlink']) {
$headerContent .= '<div>' . '<strong>' . $translationServiceObject->translate(
$labelContentLink
) . '</strong>' . ':&nbsp;' . $row['tx_sgcontentlink_contentlink'] . '</div>';
}
// Set plugin options array
$pluginOptions = GeneralUtility::xml2array($row['pi_flexform'], 'T3:');
// Get the FlexForm configuration file
$xmlFilePath = $GLOBALS['TCA']['tt_content']['columns']['pi_flexform']['config']['ds']['sgyoutube_youtube,list'];
$xmlContent = GeneralUtility::getFileAbsFileName(
str_replace(
'FILE:EXT:', 'EXT:', $xmlFilePath
)
);
// Get contents of the FlexForm configuration file
$xmlString = file_get_contents($xmlContent);
$arrayJobs = GeneralUtility::xml2array($xmlString);
// Begin rendering of table
$itemContent .= '<br>' . '<table class="table table-striped">';
// Table header
$labelSettings = 'LLL:EXT:sg_youtube/Resources/Private/Language/locallang.xlf:settings';
$labelvalue = 'LLL:EXT:sg_youtube/Resources/Private/Language/locallang.xlf:values';
$itemContent .= '<row>' . '<th style="width: 50%">' . $translationServiceObject->translate(
$labelSettings
) . '</th>';
$itemContent .= '<th style="width: 50%">' . $translationServiceObject->translate(
$labelvalue
) . '</th>' . '</tr>';
// Table content rows
// Loop through plugin options
foreach ($pluginOptions['data']['sDEF']['lDEF'] as $key => $setting) {
// if plugin option exists within the Flexform configuration file
if (array_key_exists($key, $arrayJobs['sheets']['sDEF']['ROOT']['el'])) {
// Display label
$labelId = $arrayJobs['sheets']['sDEF']['ROOT']['el'][$key]['TCEforms']['label'];
$itemContent .= '<row>' . '<td><strong>' . $translationServiceObject->translate(
trim($labelId)
) . '</strong></td>';
// Display value
$itemContent .= '<td>' . $setting['vDEF'] . '</td>' . '</tr>';
}
}
// Record Storage
if ($row['pages'] !== '') {
// Record Storage Page label
$labelRecordStorage = 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:pages.ALT.list_formlabel';
// Get storage page(s)
$backendUtilityObject = GeneralUtility::makeInstance(BackendUtility::class);
$storagePageIds = explode(',', $row['pages']);
$storagePages = [];
foreach ($storagePageIds as $i => $storagePageId) {
$storagePages[] = $backendUtilityObject->getRecord(
'pages', $storagePageId, 'title'
)['title'] . ' ' . '(' . $storagePageId . ')';
}
// Render 'Record Storage Page' row
$itemContent .= '<row>' . '<td><strong>' . $translationServiceObject->translate(
$labelRecordStorage
) . '</strong></td>';
$itemContent .= '<td>' . implode(', ', $storagePages) . '</td>' . '</tr>';
}
// End rendering of table
$itemContent .= '</table>';
$drawItem = FALSE;
}
}
}
<?xml version="1.0" encoding="utf-8" standalone="yes" ?> <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0"> <xliff version="1.0">
<file source-language="en" target-language="de" datatype="plaintext" original="messages" date="2019-12-07T19:09:30Z"> <file source-language="en" target-language="de" datatype="plaintext" original="messages" date="2020-06-10T09:14:47Z">
<header> <header>
<generator>LFEditor</generator> <generator>LFEditor</generator>
</header> </header>
...@@ -49,6 +49,14 @@ ...@@ -49,6 +49,14 @@
<source><![CDATA[Maximum Amount]]></source> <source><![CDATA[Maximum Amount]]></source>
<target><![CDATA[Maximale Anzahl]]></target> <target><![CDATA[Maximale Anzahl]]></target>
</trans-unit> </trans-unit>
<trans-unit id="settings" approved="yes">
<source><![CDATA[Settings]]></source>
<target><![CDATA[Einstellungen]]></target>
</trans-unit>
<trans-unit id="values" approved="yes">
<source><![CDATA[Values]]></source>
<target><![CDATA[Werte]]></target>
</trans-unit>
</body> </body>
</file> </file>
</xliff> </xliff>
\ No newline at end of file
...@@ -38,6 +38,12 @@ ...@@ -38,6 +38,12 @@
<trans-unit id="maxResults"> <trans-unit id="maxResults">
<source><![CDATA[Maximum Amount]]></source> <source><![CDATA[Maximum Amount]]></source>
</trans-unit> </trans-unit>
<trans-unit id="settings">
<source><![CDATA[Settings]]></source>
</trans-unit>
<trans-unit id="values">
<source><![CDATA[Values]]></source>
</trans-unit>
</body> </body>
</file> </file>
</xliff> </xliff>
\ No newline at end of file
...@@ -40,3 +40,6 @@ if (!defined('TYPO3_MODE')) { ...@@ -40,3 +40,6 @@ if (!defined('TYPO3_MODE')) {
] ]
); );
//Hooks
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem']['sg_youtube']
= \SGalinski\SgYoutube\Hooks\PluginRenderer::class;
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