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