‪TYPO3CMS  10.4
BackendLayoutWizardElement.php
Go to the documentation of this file.
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 
17 
21 
27 {
33  protected ‪$defaultFieldInformation = [
34  'tcaDescription' => [
35  'renderType' => 'tcaDescription',
36  ],
37  ];
38 
42  protected ‪$rows = [];
43 
47  protected ‪$colCount = 0;
48 
52  protected ‪$rowCount = 0;
53 
57  public function ‪render()
58  {
59  $lang = $this->‪getLanguageService();
60  $resultArray = $this->‪initializeResultArray();
61  $this->‪init();
62 
63  $fieldInformationResult = $this->‪renderFieldInformation();
64  $fieldInformationHtml = $fieldInformationResult['html'];
65  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false);
66 
67  $fieldWizardResult = $this->‪renderFieldWizard();
68  $fieldWizardHtml = $fieldWizardResult['html'];
69  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $fieldWizardResult, false);
70 
71  $json = (string)json_encode($this->rows, JSON_HEX_QUOT | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS);
72  $html = [];
73  $html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
74  $html[] = $fieldInformationHtml;
75  $html[] = '<div class="form-control-wrap">';
76  $html[] = '<div class="form-wizards-wrap">';
77  $html[] = '<div class="form-wizards-element">';
78  $html[] = '<input';
79  $html[] = ' type="hidden"';
80  $html[] = ' name="' . htmlspecialchars($this->data['parameterArray']['itemFormElName']) . '"';
81  $html[] = ' value="' . htmlspecialchars($this->data['parameterArray']['itemFormElValue']) . '"';
82  $html[] = '/>';
83  $html[] = '<table class="grideditor table table-bordered">';
84  $html[] = '<tr>';
85  $html[] = '<td colspan="2" align="center">';
86  $html[] = '<div class="btn-group">';
87  $html[] = '<a class="btn btn-default btn-sm t3js-grideditor-removerow-top" href="#"';
88  $html[] = ' title="' . htmlspecialchars($lang->getLL('grid_removeRow')) . '">';
89  $html[] = '<i class="fa fa-fw fa-minus"></i>';
90  $html[] = '</a>';
91  $html[] = '<a class="btn btn-default btn-sm t3js-grideditor-addrow-top" href="#"';
92  $html[] = ' title="' . htmlspecialchars($lang->getLL('grid_addRow')) . '">';
93  $html[] = '<i class="fa fa-fw fa-plus"></i>';
94  $html[] = '</a>';
95  $html[] = '</div>';
96  $html[] = '</td>';
97  $html[] = '</tr>';
98  $html[] = '<tr>';
99  $html[] = '<td class="editor_cell">';
100  $html[] = '<div';
101  $html[] = ' id="editor"';
102  $html[] = ' class="t3js-grideditor"';
103  $html[] = ' data-data="' . htmlspecialchars($json) . '"';
104  $html[] = ' data-rowcount="' . (int)$this->rowCount . '"';
105  $html[] = ' data-colcount="' . (int)$this->colCount . '"';
106  $html[] = ' data-field="' . htmlspecialchars($this->data['parameterArray']['itemFormElName']) . '"';
107  $html[] = '>';
108  $html[] = '</div>';
109  $html[] = '</td>';
110  $html[] = '<td>';
111  $html[] = '<div class="btn-group-vertical">';
112  $html[] = '<a class="btn btn-default btn-sm t3js-grideditor-addcolumn" href="#"';
113  $html[] = ' title="' . htmlspecialchars($lang->getLL('grid_addColumn')) . '">';
114  $html[] = '<i class="fa fa-fw fa-plus"></i>';
115  $html[] = '</a>';
116  $html[] = '<a class="btn btn-default btn-sm t3js-grideditor-removecolumn" href="#"';
117  $html[] = ' title="' . htmlspecialchars($lang->getLL('grid_removeColumn')) . '">';
118  $html[] = '<i class="fa fa-fw fa-minus"></i>';
119  $html[] = '</a>';
120  $html[] = '</div>';
121  $html[] = '</td>';
122  $html[] = '</tr>';
123  $html[] = '<tr>';
124  $html[] = '<td colspan="2" align="center">';
125  $html[] = '<div class="btn-group">';
126  $html[] = '<a class="btn btn-default btn-sm t3js-grideditor-addrow-bottom" href="#"';
127  $html[] = ' title="' . htmlspecialchars($lang->getLL('grid_addRow')) . '">';
128  $html[] = '<i class="fa fa-fw fa-plus"></i>';
129  $html[] = '</a>';
130  $html[] = '<a class="btn btn-default btn-sm t3js-grideditor-removerow-bottom" href="#"';
131  $html[] = ' title="' . htmlspecialchars($lang->getLL('grid_removeRow')) . '">';
132  $html[] = '<i class="fa fa-fw fa-minus"></i>';
133  $html[] = '</a>';
134  $html[] = '</div>';
135  $html[] = '</td>';
136  $html[] = '</tr>';
137  $html[] = '<tr>';
138  $html[] = '<td colspan="2">';
139  $html[] = '<a href="#" class="btn btn-default btn-sm t3js-grideditor-preview-button"></a>';
140  $html[] = '<pre class="t3js-grideditor-preview-config grideditor-preview"><code></code></pre>';
141  $html[] = '</td>';
142  $html[] = '</tr>';
143  $html[] = '</table>';
144  $html[] = '</div>';
145  if (!empty($fieldWizardHtml)) {
146  $html[] = '<div class="form-wizards-items-bottom">';
147  $html[] = $fieldWizardHtml;
148  $html[] = '</div>';
149  }
150  $html[] = '</div>';
151  $html[] = '</div>';
152  $html[] = '</div>';
153 
154  $html = implode(LF, $html);
155  $resultArray['html'] = $html;
156  $resultArray['requireJsModules'][] = ['TYPO3/CMS/Backend/GridEditor' => 'function(GridEditor) { new GridEditor.GridEditor(); }'];
157  $resultArray['additionalInlineLanguageLabelFiles'][] = 'EXT:core/Resources/Private/Language/locallang_wizards.xlf';
158  $resultArray['additionalInlineLanguageLabelFiles'][] = 'EXT:backend/Resources/Private/Language/locallang.xlf';
159 
160  return $resultArray;
161  }
162 
166  protected function ‪init()
167  {
168  if (empty($this->data['databaseRow']['config'])) {
169  ‪$rows = [[['colspan' => 1, 'rowspan' => 1, 'spanned' => 0, 'name' => '0x0']]];
170  ‪$colCount = 1;
171  ‪$rowCount = 1;
172  } else {
173  // load TS parser
174  ‪$parser = GeneralUtility::makeInstance(TypoScriptParser::class);
175  ‪$parser->parse($this->data['databaseRow']['config']);
176  ‪$data = ‪$parser->setup['backend_layout.'];
177  ‪$rows = [];
178  ‪$colCount = ‪$data['colCount'];
179  ‪$rowCount = ‪$data['rowCount'];
180  $dataRows = ‪$data['rows.'];
181  $spannedMatrix = [];
182  for ($i = 1; $i <= ‪$rowCount; $i++) {
183  $cells = [];
184  $row = array_shift($dataRows);
185  $columns = $row['columns.'];
186  for ($j = 1; $j <= ‪$colCount; $j++) {
187  $cellData = [];
188  if (!$spannedMatrix[$i][$j]) {
189  if (is_array($columns) && !empty($columns)) {
190  $column = array_shift($columns);
191  if (isset($column['colspan'])) {
192  $cellData['colspan'] = (int)$column['colspan'];
193  $columnColSpan = (int)$column['colspan'];
194  if (isset($column['rowspan'])) {
195  $columnRowSpan = (int)$column['rowspan'];
196  for ($spanRow = 0; $spanRow < $columnRowSpan; $spanRow++) {
197  for ($spanColumn = 0; $spanColumn < $columnColSpan; $spanColumn++) {
198  $spannedMatrix[$i + $spanRow][$j + $spanColumn] = 1;
199  }
200  }
201  } else {
202  for ($spanColumn = 0; $spanColumn < $columnColSpan; $spanColumn++) {
203  $spannedMatrix[$i][$j + $spanColumn] = 1;
204  }
205  }
206  } else {
207  $cellData['colspan'] = 1;
208  if (isset($column['rowspan'])) {
209  $columnRowSpan = (int)$column['rowspan'];
210  for ($spanRow = 0; $spanRow < $columnRowSpan; $spanRow++) {
211  $spannedMatrix[$i + $spanRow][$j] = 1;
212  }
213  }
214  }
215  if (isset($column['rowspan'])) {
216  $cellData['rowspan'] = (int)$column['rowspan'];
217  } else {
218  $cellData['rowspan'] = 1;
219  }
220  if (isset($column['name'])) {
221  $cellData['name'] = $column['name'];
222  }
223  if (isset($column['colPos'])) {
224  $cellData['column'] = (int)$column['colPos'];
225  }
226  }
227  } else {
228  $cellData = ['colspan' => 1, 'rowspan' => 1, 'spanned' => 1];
229  }
230  $cells[] = $cellData;
231  }
232  ‪$rows[] = $cells;
233  if (!empty($spannedMatrix[$i]) && is_array($spannedMatrix[$i])) {
234  ksort($spannedMatrix[$i]);
235  }
236  }
237  }
238  $this->rows = ‪$rows;
239  $this->colCount = (int)‪$colCount;
240  $this->rowCount = (int)‪$rowCount;
241  }
242 }
‪TYPO3\CMS\Backend\View\Wizard\Element\BackendLayoutWizardElement\$defaultFieldInformation
‪array $defaultFieldInformation
Definition: BackendLayoutWizardElement.php:32
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\renderFieldInformation
‪array renderFieldInformation()
Definition: AbstractFormElement.php:72
‪TYPO3\CMS\Backend\Form\AbstractNode\mergeChildReturnIntoExistingResult
‪array mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml=true)
Definition: AbstractNode.php:116
‪TYPO3\CMS\Backend\View\Wizard\Element\BackendLayoutWizardElement\init
‪init()
Definition: BackendLayoutWizardElement.php:162
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪array initializeResultArray()
Definition: AbstractNode.php:90
‪TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
Definition: TypoScriptParser.php:37
‪$parser
‪$parser
Definition: annotationChecker.php:108
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement
Definition: AbstractFormElement.php:32
‪TYPO3\CMS\Backend\View\Wizard\Element\BackendLayoutWizardElement
Definition: BackendLayoutWizardElement.php:27
‪TYPO3\CMS\Backend\View\Wizard\Element\BackendLayoutWizardElement\render
‪array render()
Definition: BackendLayoutWizardElement.php:53
‪TYPO3\CMS\Backend\View\Wizard\Element\BackendLayoutWizardElement\$rows
‪array $rows
Definition: BackendLayoutWizardElement.php:40
‪TYPO3\CMS\Backend\Form\AbstractNode\$data
‪array $data
Definition: AbstractNode.php:42
‪TYPO3\CMS\Backend\View\Wizard\Element
Definition: BackendLayoutWizardElement.php:16
‪TYPO3\CMS\Backend\View\Wizard\Element\BackendLayoutWizardElement\$rowCount
‪int $rowCount
Definition: BackendLayoutWizardElement.php:48
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\getLanguageService
‪LanguageService getLanguageService()
Definition: AbstractFormElement.php:390
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\renderFieldWizard
‪array renderFieldWizard()
Definition: AbstractFormElement.php:104
‪TYPO3\CMS\Backend\View\Wizard\Element\BackendLayoutWizardElement\$colCount
‪int $colCount
Definition: BackendLayoutWizardElement.php:44