1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Extension "sf_event_mgt" for TYPO3 CMS. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the |
9
|
|
|
* LICENSE.txt file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace DERHANSEN\SfEventMgt\Preview; |
13
|
|
|
|
14
|
|
|
use TYPO3\CMS\Backend\Preview\PreviewRendererInterface; |
|
|
|
|
15
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
|
|
|
|
16
|
|
|
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem; |
|
|
|
|
17
|
|
|
use TYPO3\CMS\Core\Imaging\Icon; |
18
|
|
|
use TYPO3\CMS\Core\Imaging\IconFactory; |
19
|
|
|
use TYPO3\CMS\Core\Localization\LanguageService; |
20
|
|
|
use TYPO3\CMS\Core\Page\PageRenderer; |
21
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
22
|
|
|
use TYPO3\CMS\Fluid\View\StandaloneView; |
|
|
|
|
23
|
|
|
|
24
|
|
|
abstract class AbstractPluginPreviewRenderer implements PreviewRendererInterface |
25
|
|
|
{ |
26
|
|
|
protected const LLPATH = 'LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:'; |
27
|
|
|
|
28
|
|
|
protected IconFactory $iconFactory; |
29
|
|
|
|
30
|
|
|
public function __construct() |
31
|
|
|
{ |
32
|
|
|
$this->iconFactory = GeneralUtility::makeInstance(IconFactory::class); |
33
|
|
|
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
34
|
|
|
$pageRenderer->addCssFile('EXT:sf_event_mgt/Resources/Public/Css/Backend/PageLayoutView.css'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Renders the header (actually empty, since header is rendered in content) |
39
|
|
|
*/ |
40
|
|
|
public function renderPageModulePreviewHeader(GridColumnItem $item): string |
41
|
|
|
{ |
42
|
|
|
return ''; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Renders the content of the plugin preview. Must be overwritten in extending class. |
47
|
|
|
*/ |
48
|
|
|
public function renderPageModulePreviewContent(GridColumnItem $item): string |
49
|
|
|
{ |
50
|
|
|
return ''; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Render the footer. Can be overwritten in extending class if required |
55
|
|
|
*/ |
56
|
|
|
public function renderPageModulePreviewFooter(GridColumnItem $item): string |
57
|
|
|
{ |
58
|
|
|
return ''; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Render the plugin preview |
63
|
|
|
*/ |
64
|
|
|
public function wrapPageModulePreview(string $previewHeader, string $previewContent, GridColumnItem $item): string |
65
|
|
|
{ |
66
|
|
|
return $previewHeader . $previewContent; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Returns the plugin name |
71
|
|
|
*/ |
72
|
|
|
protected function getPluginName(array $record): string |
73
|
|
|
{ |
74
|
|
|
$pluginId = str_replace('sfeventmgt_', '', $record['list_type']); |
75
|
|
|
return htmlspecialchars($this->getLanguageService()->sL(self::LLPATH . 'plugin.' . $pluginId . '.title')); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Returns the records flexform as array |
80
|
|
|
*/ |
81
|
|
|
protected function getFlexFormData(string $flexform): array |
82
|
|
|
{ |
83
|
|
|
$flexFormData = GeneralUtility::xml2array($flexform); |
84
|
|
|
if (!is_array($flexFormData)) { |
85
|
|
|
$flexFormData = []; |
86
|
|
|
} |
87
|
|
|
return $flexFormData; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Renders the given data and action as HTML table for plugin preview |
92
|
|
|
*/ |
93
|
|
|
protected function renderAsTable(array $data, string $pluginName = ''): string |
94
|
|
|
{ |
95
|
|
|
$view = GeneralUtility::makeInstance(StandaloneView::class); |
96
|
|
|
$view->setTemplatePathAndFilename( |
97
|
|
|
GeneralUtility::getFileAbsFileName('EXT:sf_event_mgt/Resources/Private/Backend/PageLayoutView.html') |
98
|
|
|
); |
99
|
|
|
$view->assignMultiple([ |
100
|
|
|
'data' => $data, |
101
|
|
|
'pluginName' => $pluginName, |
102
|
|
|
]); |
103
|
|
|
|
104
|
|
|
return $view->render(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Sets the PID config for the configured PID settings in plugin flexform |
109
|
|
|
*/ |
110
|
|
|
protected function setPluginPidConfig( |
111
|
|
|
array &$data, |
112
|
|
|
array $flexFormData, |
113
|
|
|
string $pidSetting, |
114
|
|
|
string $sheet = 'sDEF' |
115
|
|
|
): void { |
116
|
|
|
$pid = (int)$this->getFlexFormFieldValue($flexFormData, 'settings.' . $pidSetting, $sheet); |
117
|
|
|
if ($pid > 0) { |
118
|
|
|
$data[] = [ |
119
|
|
|
'title' => $this->getLanguageService()->sL(self::LLPATH . 'flexforms_general.' . $pidSetting), |
120
|
|
|
'value' => $this->getRecordData($pid), |
121
|
|
|
]; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Sets the storagePage configuration |
127
|
|
|
*/ |
128
|
|
|
protected function setStoragePage(array &$data, array $flexFormData, string $field): void |
129
|
|
|
{ |
130
|
|
|
$value = $this->getFlexFormFieldValue($flexFormData, $field); |
131
|
|
|
|
132
|
|
|
if (!empty($value)) { |
133
|
|
|
$pageIds = GeneralUtility::intExplode(',', $value, true); |
|
|
|
|
134
|
|
|
$pagesOut = []; |
135
|
|
|
|
136
|
|
|
foreach ($pageIds as $id) { |
137
|
|
|
$pagesOut[] = $this->getRecordData($id, 'pages'); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
$recursiveLevel = (int)$this->getFlexFormFieldValue($flexFormData, 'settings.recursive'); |
141
|
|
|
$recursiveLevelText = ''; |
142
|
|
|
if ($recursiveLevel === 250) { |
143
|
|
|
$recursiveLevelText = $this->getLanguageService()->sL('LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:recursive.I.5'); |
144
|
|
|
} elseif ($recursiveLevel > 0) { |
145
|
|
|
$recursiveLevelText = $this->getLanguageService()->sL('LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:recursive.I.' . $recursiveLevel); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
if (!empty($recursiveLevelText)) { |
149
|
|
|
$recursiveLevelText = '<br />' . |
150
|
|
|
htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.recursive')) . ' ' . |
151
|
|
|
$recursiveLevelText; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
$data[] = [ |
155
|
|
|
'title' => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.startingpoint'), |
156
|
|
|
'value' => implode(', ', $pagesOut) . $recursiveLevelText, |
157
|
|
|
]; |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Sets information to the data array if override demand setting is disabled |
163
|
|
|
*/ |
164
|
|
|
protected function setOverrideDemandSettings(array &$data, array $flexFormData, array $record): void |
165
|
|
|
{ |
166
|
|
|
$field = (int)$this->getFlexFormFieldValue($flexFormData, 'settings.disableOverrideDemand', 'additional'); |
167
|
|
|
|
168
|
|
|
if ($field === 1) { |
169
|
|
|
$text = ''; |
170
|
|
|
|
171
|
|
|
// Check if plugin action is "calendar" and if so, show warning that calendar action will not work |
172
|
|
|
if ($record['list_type'] === 'sfeventmgt_pieventcalendar') { |
173
|
|
|
$text .= ' <span class="badge badge-danger ms-1">' . |
174
|
|
|
htmlspecialchars($this->getLanguageService()->sL(self::LLPATH . 'flexforms_general.pluginCalendarMisonfiguration')) . '</span>'; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
$data[] = [ |
178
|
|
|
'title' => $this->getLanguageService()->sL(self::LLPATH . 'flexforms_general.disableOverrideDemand'), |
179
|
|
|
'value' => $text, |
180
|
|
|
'icon' => 'actions-check-square', |
181
|
|
|
]; |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Sets the order settings |
187
|
|
|
*/ |
188
|
|
|
protected function setOrderSettings( |
189
|
|
|
array &$data, |
190
|
|
|
array $flexFormData, |
191
|
|
|
string $orderByField, |
192
|
|
|
string $orderDirectionField |
193
|
|
|
): void { |
194
|
|
|
$orderField = $this->getFlexFormFieldValue($flexFormData, $orderByField); |
195
|
|
|
if (!empty($orderField)) { |
196
|
|
|
$text = $this->getLanguageService()->sL(self::LLPATH . 'flexforms_general.orderField.' . $orderField); |
197
|
|
|
|
198
|
|
|
// Order direction (asc, desc) |
199
|
|
|
$orderDirection = $this->getOrderDirectionSetting($flexFormData, $orderDirectionField); |
200
|
|
|
if ($orderDirection) { |
201
|
|
|
$text .= ', ' . strtolower($orderDirection); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
$data[] = [ |
205
|
|
|
'title' => $this->getLanguageService()->sL(self::LLPATH . 'flexforms_general.orderField'), |
206
|
|
|
'value' => $text, |
207
|
|
|
]; |
208
|
|
|
} |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Returns field value from flexform configuration, including checks if flexform configuration is available |
213
|
|
|
*/ |
214
|
|
|
protected function getFlexFormFieldValue(array $flexformData, string $key, string $sheet = 'sDEF'): ?string |
215
|
|
|
{ |
216
|
|
|
return $flexformData['data'][$sheet]['lDEF'][$key]['vDEF'] ?? ''; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Returns the record data item |
221
|
|
|
*/ |
222
|
|
|
protected function getRecordData(int $id, string $table = 'pages'): string |
223
|
|
|
{ |
224
|
|
|
$content = ''; |
225
|
|
|
$record = BackendUtility::getRecord($table, $id); |
226
|
|
|
|
227
|
|
|
if (is_array($record)) { |
228
|
|
|
$data = '<span data-toggle="tooltip" data-placement="top" data-title="id=' . $record['uid'] . '">' |
229
|
|
|
. $this->iconFactory->getIconForRecord($table, $record, Icon::SIZE_SMALL)->render() |
230
|
|
|
. '</span> '; |
231
|
|
|
$content = BackendUtility::wrapClickMenuOnIcon($data, $table, $record['uid'], '', $record); |
232
|
|
|
|
233
|
|
|
$linkTitle = htmlspecialchars(BackendUtility::getRecordTitle($table, $record)); |
234
|
|
|
$content .= $linkTitle; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
return $content; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Returns order direction |
242
|
|
|
*/ |
243
|
|
|
private function getOrderDirectionSetting(array $flexFormData, string $orderDirectionField): string |
244
|
|
|
{ |
245
|
|
|
$text = ''; |
246
|
|
|
|
247
|
|
|
$orderDirection = $this->getFlexFormFieldValue($flexFormData, $orderDirectionField); |
248
|
|
|
if (!empty($orderDirection)) { |
249
|
|
|
$text = $this->getLanguageService()->sL(self::LLPATH . 'flexforms_general.orderDirection.' . $orderDirection . 'ending'); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
return $text; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
protected function getLanguageService(): LanguageService |
256
|
|
|
{ |
257
|
|
|
return $GLOBALS['LANG']; |
258
|
|
|
} |
259
|
|
|
} |
260
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths