|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the TYPO3 CMS project. |
|
5
|
|
|
* |
|
6
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
7
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
8
|
|
|
* of the License, or any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please read the |
|
11
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
12
|
|
|
* |
|
13
|
|
|
* The TYPO3 project - inspiring people to share! |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace TYPO3\CMS\Backend\Form\Element; |
|
17
|
|
|
|
|
18
|
|
|
use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser; |
|
19
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Backend layout element |
|
23
|
|
|
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API. |
|
24
|
|
|
*/ |
|
25
|
|
|
class BackendLayoutWizardElement extends AbstractFormElement |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* Default field information enabled for this element. |
|
29
|
|
|
* |
|
30
|
|
|
* @var array |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $defaultFieldInformation = [ |
|
33
|
|
|
'tcaDescription' => [ |
|
34
|
|
|
'renderType' => 'tcaDescription', |
|
35
|
|
|
], |
|
36
|
|
|
]; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var array |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $rows = []; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var int |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $colCount = 0; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var int |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $rowCount = 0; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return array |
|
55
|
|
|
*/ |
|
56
|
|
|
public function render() |
|
57
|
|
|
{ |
|
58
|
|
|
$lang = $this->getLanguageService(); |
|
59
|
|
|
$resultArray = $this->initializeResultArray(); |
|
60
|
|
|
$this->init(); |
|
61
|
|
|
|
|
62
|
|
|
$fieldInformationResult = $this->renderFieldInformation(); |
|
63
|
|
|
$fieldInformationHtml = $fieldInformationResult['html']; |
|
64
|
|
|
$resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false); |
|
65
|
|
|
|
|
66
|
|
|
$fieldWizardResult = $this->renderFieldWizard(); |
|
67
|
|
|
$fieldWizardHtml = $fieldWizardResult['html']; |
|
68
|
|
|
$resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldWizardResult, false); |
|
69
|
|
|
|
|
70
|
|
|
$json = (string)json_encode($this->rows, JSON_HEX_QUOT | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS); |
|
71
|
|
|
$html = []; |
|
72
|
|
|
$html[] = '<div class="formengine-field-item t3js-formengine-field-item">'; |
|
73
|
|
|
$html[] = $fieldInformationHtml; |
|
74
|
|
|
$html[] = '<div class="form-control-wrap">'; |
|
75
|
|
|
$html[] = '<div class="form-wizards-wrap">'; |
|
76
|
|
|
$html[] = '<div class="form-wizards-element">'; |
|
77
|
|
|
$html[] = '<input'; |
|
78
|
|
|
$html[] = ' type="hidden"'; |
|
79
|
|
|
$html[] = ' name="' . htmlspecialchars($this->data['parameterArray']['itemFormElName']) . '"'; |
|
80
|
|
|
$html[] = ' value="' . htmlspecialchars($this->data['parameterArray']['itemFormElValue']) . '"'; |
|
81
|
|
|
$html[] = '/>'; |
|
82
|
|
|
$html[] = '<table class="grideditor table table-bordered">'; |
|
83
|
|
|
$html[] = '<tr>'; |
|
84
|
|
|
$html[] = '<td colspan="2" align="center">'; |
|
85
|
|
|
$html[] = '<div class="btn-group">'; |
|
86
|
|
|
$html[] = '<a class="btn btn-default btn-sm t3js-grideditor-removerow-top" href="#"'; |
|
87
|
|
|
$html[] = ' title="' . htmlspecialchars($lang->getLL('grid_removeRow')) . '">'; |
|
88
|
|
|
$html[] = '<i class="fa fa-fw fa-minus"></i>'; |
|
89
|
|
|
$html[] = '</a>'; |
|
90
|
|
|
$html[] = '<a class="btn btn-default btn-sm t3js-grideditor-addrow-top" href="#"'; |
|
91
|
|
|
$html[] = ' title="' . htmlspecialchars($lang->getLL('grid_addRow')) . '">'; |
|
92
|
|
|
$html[] = '<i class="fa fa-fw fa-plus"></i>'; |
|
93
|
|
|
$html[] = '</a>'; |
|
94
|
|
|
$html[] = '</div>'; |
|
95
|
|
|
$html[] = '</td>'; |
|
96
|
|
|
$html[] = '</tr>'; |
|
97
|
|
|
$html[] = '<tr>'; |
|
98
|
|
|
$html[] = '<td class="editor_cell">'; |
|
99
|
|
|
$html[] = '<div'; |
|
100
|
|
|
$html[] = ' id="editor"'; |
|
101
|
|
|
$html[] = ' class="t3js-grideditor"'; |
|
102
|
|
|
$html[] = ' data-data="' . htmlspecialchars($json) . '"'; |
|
103
|
|
|
$html[] = ' data-rowcount="' . (int)$this->rowCount . '"'; |
|
104
|
|
|
$html[] = ' data-colcount="' . (int)$this->colCount . '"'; |
|
105
|
|
|
$html[] = ' data-field="' . htmlspecialchars($this->data['parameterArray']['itemFormElName']) . '"'; |
|
106
|
|
|
$html[] = '>'; |
|
107
|
|
|
$html[] = '</div>'; |
|
108
|
|
|
$html[] = '</td>'; |
|
109
|
|
|
$html[] = '<td>'; |
|
110
|
|
|
$html[] = '<div class="btn-group-vertical">'; |
|
111
|
|
|
$html[] = '<a class="btn btn-default btn-sm t3js-grideditor-addcolumn" href="#"'; |
|
112
|
|
|
$html[] = ' title="' . htmlspecialchars($lang->getLL('grid_addColumn')) . '">'; |
|
113
|
|
|
$html[] = '<i class="fa fa-fw fa-plus"></i>'; |
|
114
|
|
|
$html[] = '</a>'; |
|
115
|
|
|
$html[] = '<a class="btn btn-default btn-sm t3js-grideditor-removecolumn" href="#"'; |
|
116
|
|
|
$html[] = ' title="' . htmlspecialchars($lang->getLL('grid_removeColumn')) . '">'; |
|
117
|
|
|
$html[] = '<i class="fa fa-fw fa-minus"></i>'; |
|
118
|
|
|
$html[] = '</a>'; |
|
119
|
|
|
$html[] = '</div>'; |
|
120
|
|
|
$html[] = '</td>'; |
|
121
|
|
|
$html[] = '</tr>'; |
|
122
|
|
|
$html[] = '<tr>'; |
|
123
|
|
|
$html[] = '<td colspan="2" align="center">'; |
|
124
|
|
|
$html[] = '<div class="btn-group">'; |
|
125
|
|
|
$html[] = '<a class="btn btn-default btn-sm t3js-grideditor-addrow-bottom" href="#"'; |
|
126
|
|
|
$html[] = ' title="' . htmlspecialchars($lang->getLL('grid_addRow')) . '">'; |
|
127
|
|
|
$html[] = '<i class="fa fa-fw fa-plus"></i>'; |
|
128
|
|
|
$html[] = '</a>'; |
|
129
|
|
|
$html[] = '<a class="btn btn-default btn-sm t3js-grideditor-removerow-bottom" href="#"'; |
|
130
|
|
|
$html[] = ' title="' . htmlspecialchars($lang->getLL('grid_removeRow')) . '">'; |
|
131
|
|
|
$html[] = '<i class="fa fa-fw fa-minus"></i>'; |
|
132
|
|
|
$html[] = '</a>'; |
|
133
|
|
|
$html[] = '</div>'; |
|
134
|
|
|
$html[] = '</td>'; |
|
135
|
|
|
$html[] = '</tr>'; |
|
136
|
|
|
$html[] = '<tr>'; |
|
137
|
|
|
$html[] = '<td colspan="2">'; |
|
138
|
|
|
$html[] = '<a href="#" class="btn btn-default btn-sm t3js-grideditor-preview-button"></a>'; |
|
139
|
|
|
$html[] = '<pre class="t3js-grideditor-preview-config grideditor-preview"><code></code></pre>'; |
|
140
|
|
|
$html[] = '</td>'; |
|
141
|
|
|
$html[] = '</tr>'; |
|
142
|
|
|
$html[] = '</table>'; |
|
143
|
|
|
$html[] = '</div>'; |
|
144
|
|
|
if (!empty($fieldWizardHtml)) { |
|
145
|
|
|
$html[] = '<div class="form-wizards-items-bottom">'; |
|
146
|
|
|
$html[] = $fieldWizardHtml; |
|
147
|
|
|
$html[] = '</div>'; |
|
148
|
|
|
} |
|
149
|
|
|
$html[] = '</div>'; |
|
150
|
|
|
$html[] = '</div>'; |
|
151
|
|
|
$html[] = '</div>'; |
|
152
|
|
|
|
|
153
|
|
|
$html = implode(LF, $html); |
|
154
|
|
|
$resultArray['html'] = $html; |
|
155
|
|
|
$resultArray['requireJsModules'][] = ['TYPO3/CMS/Backend/GridEditor' => 'function(GridEditor) { new GridEditor.GridEditor(); }']; |
|
156
|
|
|
$resultArray['additionalInlineLanguageLabelFiles'][] = 'EXT:core/Resources/Private/Language/locallang_wizards.xlf'; |
|
157
|
|
|
$resultArray['additionalInlineLanguageLabelFiles'][] = 'EXT:backend/Resources/Private/Language/locallang.xlf'; |
|
158
|
|
|
|
|
159
|
|
|
return $resultArray; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Initialize wizard |
|
164
|
|
|
*/ |
|
165
|
|
|
protected function init() |
|
166
|
|
|
{ |
|
167
|
|
|
if (empty($this->data['databaseRow']['config'])) { |
|
168
|
|
|
$rows = [[['colspan' => 1, 'rowspan' => 1, 'spanned' => 0, 'name' => '0x0']]]; |
|
169
|
|
|
$colCount = 1; |
|
170
|
|
|
$rowCount = 1; |
|
171
|
|
|
} else { |
|
172
|
|
|
// load TS parser |
|
173
|
|
|
$parser = GeneralUtility::makeInstance(TypoScriptParser::class); |
|
174
|
|
|
$parser->parse($this->data['databaseRow']['config']); |
|
175
|
|
|
$data = $parser->setup['backend_layout.']; |
|
176
|
|
|
$rows = []; |
|
177
|
|
|
$colCount = $data['colCount']; |
|
178
|
|
|
$rowCount = $data['rowCount']; |
|
179
|
|
|
$dataRows = $data['rows.']; |
|
180
|
|
|
$spannedMatrix = []; |
|
181
|
|
|
for ($i = 1; $i <= $rowCount; $i++) { |
|
182
|
|
|
$cells = []; |
|
183
|
|
|
$row = array_shift($dataRows); |
|
184
|
|
|
$columns = $row['columns.']; |
|
185
|
|
|
for ($j = 1; $j <= $colCount; $j++) { |
|
186
|
|
|
$cellData = []; |
|
187
|
|
|
if (!$spannedMatrix[$i][$j]) { |
|
188
|
|
|
if (is_array($columns) && !empty($columns)) { |
|
189
|
|
|
$column = array_shift($columns); |
|
190
|
|
|
if (isset($column['colspan'])) { |
|
191
|
|
|
$cellData['colspan'] = (int)$column['colspan']; |
|
192
|
|
|
$columnColSpan = (int)$column['colspan']; |
|
193
|
|
|
if (isset($column['rowspan'])) { |
|
194
|
|
|
$columnRowSpan = (int)$column['rowspan']; |
|
195
|
|
|
for ($spanRow = 0; $spanRow < $columnRowSpan; $spanRow++) { |
|
196
|
|
|
for ($spanColumn = 0; $spanColumn < $columnColSpan; $spanColumn++) { |
|
197
|
|
|
$spannedMatrix[$i + $spanRow][$j + $spanColumn] = 1; |
|
198
|
|
|
} |
|
199
|
|
|
} |
|
200
|
|
|
} else { |
|
201
|
|
|
for ($spanColumn = 0; $spanColumn < $columnColSpan; $spanColumn++) { |
|
202
|
|
|
$spannedMatrix[$i][$j + $spanColumn] = 1; |
|
203
|
|
|
} |
|
204
|
|
|
} |
|
205
|
|
|
} else { |
|
206
|
|
|
$cellData['colspan'] = 1; |
|
207
|
|
|
if (isset($column['rowspan'])) { |
|
208
|
|
|
$columnRowSpan = (int)$column['rowspan']; |
|
209
|
|
|
for ($spanRow = 0; $spanRow < $columnRowSpan; $spanRow++) { |
|
210
|
|
|
$spannedMatrix[$i + $spanRow][$j] = 1; |
|
211
|
|
|
} |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
if (isset($column['rowspan'])) { |
|
215
|
|
|
$cellData['rowspan'] = (int)$column['rowspan']; |
|
216
|
|
|
} else { |
|
217
|
|
|
$cellData['rowspan'] = 1; |
|
218
|
|
|
} |
|
219
|
|
|
if (isset($column['name'])) { |
|
220
|
|
|
$cellData['name'] = $column['name']; |
|
221
|
|
|
} |
|
222
|
|
|
if (isset($column['colPos'])) { |
|
223
|
|
|
$cellData['column'] = (int)$column['colPos']; |
|
224
|
|
|
} |
|
225
|
|
|
} |
|
226
|
|
|
} else { |
|
227
|
|
|
$cellData = ['colspan' => 1, 'rowspan' => 1, 'spanned' => 1]; |
|
228
|
|
|
} |
|
229
|
|
|
$cells[] = $cellData; |
|
230
|
|
|
} |
|
231
|
|
|
$rows[] = $cells; |
|
232
|
|
|
if (!empty($spannedMatrix[$i]) && is_array($spannedMatrix[$i])) { |
|
233
|
|
|
ksort($spannedMatrix[$i]); |
|
234
|
|
|
} |
|
235
|
|
|
} |
|
236
|
|
|
} |
|
237
|
|
|
$this->rows = $rows; |
|
238
|
|
|
$this->colCount = (int)$colCount; |
|
239
|
|
|
$this->rowCount = (int)$rowCount; |
|
240
|
|
|
} |
|
241
|
|
|
} |
|
242
|
|
|
|