Commit e8a3ea87 authored by Oliver Bartsch's avatar Oliver Bartsch
Browse files

[BUGFIX] Do not use hardcoded field name for belayoutwizard

TCA renderType=belayoutwizard did previously not
work for custom fields, as can be seen in styleguide
`tx_styleguide_elements_basic.text_20`.

BackendLayoutWizardElement used the hardcoded
field name "config", which however is only used for
the "backend_layout" table. Additionally, using the
raw database value instead of the processed
"itemFormElValue" led to further issues, e.g. when
the field is defined with "l10n_display=defaultAsReadonly".

This is now fixed by using the "itemFormElValue",
since this is the correct value, which is also added
to the corresponding input field and would also
contain the "default" for new records.

Additionally, the given parsed itemFormElValue is
now checked to start with the correct root level
key "backend_layout.". This prevents undefined
array key warnings, triggered when a malformed
default value is used for the field.

Resolves: #96060
Releases: master, 11.5
Change-Id: I2d7c40bf3b33d6d2528c7575febe67d105ab5e12
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72276

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Jochen's avatarJochen <rothjochen@gmail.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Jochen's avatarJochen <rothjochen@gmail.com>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
parent 04b5ffcf
......@@ -195,76 +195,81 @@ class BackendLayoutWizardElement extends AbstractFormElement
*/
protected function init()
{
if (empty($this->data['databaseRow']['config'])) {
$rows = [[['colspan' => 1, 'rowspan' => 1, 'spanned' => 0, 'name' => '0x0']]];
$colCount = 1;
$rowCount = 1;
} else {
// load TS parser
// Initialize default values
$rows = [[['colspan' => 1, 'rowspan' => 1, 'spanned' => 0, 'name' => '0x0']]];
$colCount = 1;
$rowCount = 1;
if (!empty($this->data['parameterArray']['itemFormElValue'])) {
// load TS parser in case we already have a config (e.g. database value or default from TCA)
$parser = GeneralUtility::makeInstance(TypoScriptParser::class);
$parser->parse($this->data['databaseRow']['config']);
$data = $parser->setup['backend_layout.'];
$rows = [];
$colCount = $data['colCount'];
$rowCount = $data['rowCount'];
$dataRows = $data['rows.'];
$spannedMatrix = [];
for ($i = 1; $i <= $rowCount; $i++) {
$cells = [];
$row = array_shift($dataRows);
$columns = $row['columns.'];
for ($j = 1; $j <= $colCount; $j++) {
$cellData = [];
if (!($spannedMatrix[$i][$j] ?? false)) {
if (is_array($columns) && !empty($columns)) {
$column = array_shift($columns);
if (isset($column['colspan'])) {
$cellData['colspan'] = (int)$column['colspan'];
$columnColSpan = (int)$column['colspan'];
if (isset($column['rowspan'])) {
$columnRowSpan = (int)$column['rowspan'];
for ($spanRow = 0; $spanRow < $columnRowSpan; $spanRow++) {
$parser->parse($this->data['parameterArray']['itemFormElValue']);
if (is_array($parser->setup['backend_layout.'] ?? false)) {
// Only evaluate, in case the "backend_layout." array exists on root level
$data = $parser->setup['backend_layout.'];
$rows = [];
$colCount = $data['colCount'];
$rowCount = $data['rowCount'];
$dataRows = $data['rows.'];
$spannedMatrix = [];
for ($i = 1; $i <= $rowCount; $i++) {
$cells = [];
$row = array_shift($dataRows);
$columns = $row['columns.'];
for ($j = 1; $j <= $colCount; $j++) {
$cellData = [];
if (!($spannedMatrix[$i][$j] ?? false)) {
if (is_array($columns) && !empty($columns)) {
$column = array_shift($columns);
if (isset($column['colspan'])) {
$cellData['colspan'] = (int)$column['colspan'];
$columnColSpan = (int)$column['colspan'];
if (isset($column['rowspan'])) {
$columnRowSpan = (int)$column['rowspan'];
for ($spanRow = 0; $spanRow < $columnRowSpan; $spanRow++) {
for ($spanColumn = 0; $spanColumn < $columnColSpan; $spanColumn++) {
$spannedMatrix[$i + $spanRow][$j + $spanColumn] = 1;
}
}
} else {
for ($spanColumn = 0; $spanColumn < $columnColSpan; $spanColumn++) {
$spannedMatrix[$i + $spanRow][$j + $spanColumn] = 1;
$spannedMatrix[$i][$j + $spanColumn] = 1;
}
}
} else {
for ($spanColumn = 0; $spanColumn < $columnColSpan; $spanColumn++) {
$spannedMatrix[$i][$j + $spanColumn] = 1;
$cellData['colspan'] = 1;
if (isset($column['rowspan'])) {
$columnRowSpan = (int)$column['rowspan'];
for ($spanRow = 0; $spanRow < $columnRowSpan; $spanRow++) {
$spannedMatrix[$i + $spanRow][$j] = 1;
}
}
}
} else {
$cellData['colspan'] = 1;
if (isset($column['rowspan'])) {
$columnRowSpan = (int)$column['rowspan'];
for ($spanRow = 0; $spanRow < $columnRowSpan; $spanRow++) {
$spannedMatrix[$i + $spanRow][$j] = 1;
}
$cellData['rowspan'] = (int)$column['rowspan'];
} else {
$cellData['rowspan'] = 1;
}
if (isset($column['name'])) {
$cellData['name'] = $column['name'];
}
if (isset($column['colPos'])) {
$cellData['column'] = (int)$column['colPos'];
}
}
if (isset($column['rowspan'])) {
$cellData['rowspan'] = (int)$column['rowspan'];
} else {
$cellData['rowspan'] = 1;
}
if (isset($column['name'])) {
$cellData['name'] = $column['name'];
}
if (isset($column['colPos'])) {
$cellData['column'] = (int)$column['colPos'];
}
} else {
$cellData = ['colspan' => 1, 'rowspan' => 1, 'spanned' => 1];
}
} else {
$cellData = ['colspan' => 1, 'rowspan' => 1, 'spanned' => 1];
$cells[] = $cellData;
}
$rows[] = $cells;
if (!empty($spannedMatrix[$i]) && is_array($spannedMatrix[$i])) {
ksort($spannedMatrix[$i]);
}
$cells[] = $cellData;
}
$rows[] = $cells;
if (!empty($spannedMatrix[$i]) && is_array($spannedMatrix[$i])) {
ksort($spannedMatrix[$i]);
}
}
}
$this->rows = $rows;
$this->colCount = (int)$colCount;
$this->rowCount = (int)$rowCount;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment