Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?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']
);
$labelSubheader = BackendUtility::getItemLabel(
'tt_content', 'subheader'
);
// Instantiate TranslationService class
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
$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'] . '>';
}
}
// Subheader
if ($row['subheader']) {
$headerContent .= '<div>' . '<strong>' . $translationServiceObject->translate(
$labelSubheader
) . '</strong>' . ': ' . $row['subheader'] . '</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 = array();
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;
}
}
}