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