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

[BUGFIX] Properly handle readOnly in BackendLayoutWizardElement

While the "readOnly" option is not supported as
columns config for renderType "belayoutwizard",
it might be automatically set by FormEngine in
case the field is defined with "l10n_display",
set to "defaultAsReadonly".

This is now properly handled.

Resolves: #96095
Related: #89152
Releases: main, 11.5
Change-Id: I2a5e3a96db66603d36633c72cf36407b21b90438
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72317


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Jochen's avatarJochen <rothjochen@gmail.com>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Jochen's avatarJochen <rothjochen@gmail.com>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
parent 255e701d
......@@ -45,6 +45,7 @@ export class GridEditor {
protected colCount: number = 1;
protected rowCount: number = 1;
protected readOnly: boolean = false;
protected field: JQuery;
protected data: any[];
protected nameLabel: string = 'name';
......@@ -63,8 +64,6 @@ export class GridEditor {
protected selectorLinkShrinkLeft: string = '.t3js-grideditor-link-shrink-left';
protected selectorLinkExpandDown: string = '.t3js-grideditor-link-expand-down';
protected selectorLinkShrinkUp: string = '.t3js-grideditor-link-shrink-up';
protected selectorDocHeaderSave: string = '.t3js-grideditor-savedok';
protected selectorDocHeaderSaveClose: string = '.t3js-grideditor-savedokclose';
protected selectorConfigPreview: string = '.t3js-grideditor-preview-config';
protected selectorPreviewArea: string = '.t3js-tsconfig-preview-area';
protected selectorCodeMirror: string = '.t3js-grideditor-preview-config .CodeMirror';
......@@ -88,6 +87,7 @@ export class GridEditor {
const $element = $(this.selectorEditor);
this.colCount = $element.data('colcount');
this.rowCount = $element.data('rowcount');
this.readOnly = $element.data('readonly');
this.field = $('input[name="' + $element.data('field') + '"]');
this.data = $element.data('data');
this.nameLabel = config !== null ? config.nameLabel : 'Name';
......@@ -104,6 +104,10 @@ export class GridEditor {
*
*/
protected initializeEvents(): void {
if (this.readOnly) {
// Do not initialize events in case this is a readonly field
return;
}
$(document).on('click', this.selectorAddColumn, this.addColumnHandler);
$(document).on('click', this.selectorRemoveColumn, this.removeColumnHandler);
$(document).on('click', this.selectorAddRowTop, this.addRowTopHandler);
......@@ -506,48 +510,53 @@ export class GridEditor {
height: parseInt(percentRow.toString(), 10) * cell.rowspan + '%',
width: parseInt(percentCol.toString(), 10) * cell.colspan + '%',
});
const $container = $('<div class="cell_container">');
$cell.append($container);
const $anchor = $('<a href="#" data-col="' + col + '" data-row="' + row + '">');
$container.append(
$anchor
.clone()
.attr('class', 't3js-grideditor-link-editor link link_editor')
.attr('title', TYPO3.lang.grid_editCell),
);
if (this.cellCanSpanRight(col, row)) {
$container.append(
$anchor
.clone()
.attr('class', 't3js-grideditor-link-expand-right link link_expand_right')
.attr('title', TYPO3.lang.grid_mergeCell),
);
}
if (this.cellCanShrinkLeft(col, row)) {
$container.append(
$anchor
.clone()
.attr('class', 't3js-grideditor-link-shrink-left link link_shrink_left')
.attr('title', TYPO3.lang.grid_splitCell),
);
}
if (this.cellCanSpanDown(col, row)) {
$container.append(
$anchor
.clone()
.attr('class', 't3js-grideditor-link-expand-down link link_expand_down')
.attr('title', TYPO3.lang.grid_mergeCell),
);
}
if (this.cellCanShrinkUp(col, row)) {
if (!this.readOnly) {
// Add cell container and actions in case this isn't a readonly field
const $container = $('<div class="cell_container">');
$cell.append($container);
const $anchor = $('<a href="#" data-col="' + col + '" data-row="' + row + '">');
$container.append(
$anchor
.clone()
.attr('class', 't3js-grideditor-link-shrink-up link link_shrink_up')
.attr('title', TYPO3.lang.grid_splitCell),
.attr('class', 't3js-grideditor-link-editor link link_editor')
.attr('title', TYPO3.lang.grid_editCell),
);
if (this.cellCanSpanRight(col, row)) {
$container.append(
$anchor
.clone()
.attr('class', 't3js-grideditor-link-expand-right link link_expand_right')
.attr('title', TYPO3.lang.grid_mergeCell),
);
}
if (this.cellCanShrinkLeft(col, row)) {
$container.append(
$anchor
.clone()
.attr('class', 't3js-grideditor-link-shrink-left link link_shrink_left')
.attr('title', TYPO3.lang.grid_splitCell),
);
}
if (this.cellCanSpanDown(col, row)) {
$container.append(
$anchor
.clone()
.attr('class', 't3js-grideditor-link-expand-down link link_expand_down')
.attr('title', TYPO3.lang.grid_mergeCell),
);
}
if (this.cellCanShrinkUp(col, row)) {
$container.append(
$anchor
.clone()
.attr('class', 't3js-grideditor-link-shrink-up link link_shrink_up')
.attr('title', TYPO3.lang.grid_splitCell),
);
}
}
$cell.append(
$('<div class="cell_data">')
.html(
......
......@@ -61,6 +61,18 @@ class BackendLayoutWizardElement extends AbstractFormElement
$resultArray = $this->initializeResultArray();
$this->init();
$row = $this->data['databaseRow'];
$tca = $this->data['processedTca'];
$parameterArray = $this->data['parameterArray'];
// readOnly is not supported as columns config but might be set by SingleFieldContainer in case
// "l10n_display" is set to "defaultAsReadonly". To prevent misbehaviour for fields, which falsely
// set this, we also check for "defaultAsReadonly" being set and whether the record is an overlay.
$readOnly = ($parameterArray['fieldConf']['config']['readOnly'] ?? false)
&& ($tca['ctrl']['transOrigPointerField'] ?? false)
&& ($row[$tca['ctrl']['transOrigPointerField']][0] ?? $row[$tca['ctrl']['transOrigPointerField']] ?? false)
&& GeneralUtility::inList($parameterArray['fieldConf']['l10n_display'] ?? '', 'defaultAsReadonly');
$fieldInformationResult = $this->renderFieldInformation();
$fieldInformationHtml = $fieldInformationResult['html'];
$resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false);
......@@ -109,20 +121,22 @@ class BackendLayoutWizardElement extends AbstractFormElement
$html[] = ' value="' . htmlspecialchars($this->data['parameterArray']['itemFormElValue']) . '"';
$html[] = '/>';
$html[] = '<table class="grideditor table table-bordered">';
$html[] = '<tr>';
$html[] = '<td colspan="2" align="center">';
$html[] = '<div class="btn-group">';
$html[] = '<a class="btn btn-default btn-sm t3js-grideditor-removerow-top" href="#"';
$html[] = ' title="' . htmlspecialchars($lang->getLL('grid_removeRow')) . '">';
$html[] = '<i class="fa fa-fw fa-minus"></i>';
$html[] = '</a>';
$html[] = '<a class="btn btn-default btn-sm t3js-grideditor-addrow-top" href="#"';
$html[] = ' title="' . htmlspecialchars($lang->getLL('grid_addRow')) . '">';
$html[] = '<i class="fa fa-fw fa-plus"></i>';
$html[] = '</a>';
$html[] = '</div>';
$html[] = '</td>';
$html[] = '</tr>';
if (!$readOnly) {
$html[] = '<tr>';
$html[] = '<td colspan="2" align="center">';
$html[] = '<div class="btn-group">';
$html[] = '<a class="btn btn-default btn-sm t3js-grideditor-removerow-top" href="#"';
$html[] = ' title="' . htmlspecialchars($lang->getLL('grid_removeRow')) . '">';
$html[] = '<i class="fa fa-fw fa-minus"></i>';
$html[] = '</a>';
$html[] = '<a class="btn btn-default btn-sm t3js-grideditor-addrow-top" href="#"';
$html[] = ' title="' . htmlspecialchars($lang->getLL('grid_addRow')) . '">';
$html[] = '<i class="fa fa-fw fa-plus"></i>';
$html[] = '</a>';
$html[] = '</div>';
$html[] = '</td>';
$html[] = '</tr>';
}
$html[] = '<tr>';
$html[] = '<td class="editor_cell">';
$html[] = '<div';
......@@ -131,36 +145,39 @@ class BackendLayoutWizardElement extends AbstractFormElement
$html[] = ' data-data="' . htmlspecialchars($json) . '"';
$html[] = ' data-rowcount="' . (int)$this->rowCount . '"';
$html[] = ' data-colcount="' . (int)$this->colCount . '"';
$html[] = ' data-readonly="' . ($readOnly ? '1' : '0') . '"';
$html[] = ' data-field="' . htmlspecialchars($this->data['parameterArray']['itemFormElName']) . '"';
$html[] = '>';
$html[] = '</div>';
$html[] = '</td>';
$html[] = '<td>';
$html[] = '<div class="btn-group-vertical">';
$html[] = '<a class="btn btn-default btn-sm t3js-grideditor-addcolumn" href="#"';
$html[] = ' title="' . htmlspecialchars($lang->getLL('grid_addColumn')) . '">';
$html[] = '<i class="fa fa-fw fa-plus"></i>';
$html[] = '</a>';
$html[] = '<a class="btn btn-default btn-sm t3js-grideditor-removecolumn" href="#"';
$html[] = ' title="' . htmlspecialchars($lang->getLL('grid_removeColumn')) . '">';
$html[] = '<i class="fa fa-fw fa-minus"></i>';
$html[] = '</a>';
$html[] = '</div>';
$html[] = '</td>';
$html[] = '</tr>';
$html[] = '<tr>';
$html[] = '<td colspan="2" align="center">';
$html[] = '<div class="btn-group">';
$html[] = '<a class="btn btn-default btn-sm t3js-grideditor-addrow-bottom" href="#"';
$html[] = ' title="' . htmlspecialchars($lang->getLL('grid_addRow')) . '">';
$html[] = '<i class="fa fa-fw fa-plus"></i>';
$html[] = '</a>';
$html[] = '<a class="btn btn-default btn-sm t3js-grideditor-removerow-bottom" href="#"';
$html[] = ' title="' . htmlspecialchars($lang->getLL('grid_removeRow')) . '">';
$html[] = '<i class="fa fa-fw fa-minus"></i>';
$html[] = '</a>';
$html[] = '</div>';
$html[] = '</td>';
if (!$readOnly) {
$html[] = '<td>';
$html[] = '<div class="btn-group-vertical">';
$html[] = '<a class="btn btn-default btn-sm t3js-grideditor-addcolumn" href="#"';
$html[] = ' title="' . htmlspecialchars($lang->getLL('grid_addColumn')) . '">';
$html[] = '<i class="fa fa-fw fa-plus"></i>';
$html[] = '</a>';
$html[] = '<a class="btn btn-default btn-sm t3js-grideditor-removecolumn" href="#"';
$html[] = ' title="' . htmlspecialchars($lang->getLL('grid_removeColumn')) . '">';
$html[] = '<i class="fa fa-fw fa-minus"></i>';
$html[] = '</a>';
$html[] = '</div>';
$html[] = '</td>';
$html[] = '</tr>';
$html[] = '<tr>';
$html[] = '<td colspan="2" align="center">';
$html[] = '<div class="btn-group">';
$html[] = '<a class="btn btn-default btn-sm t3js-grideditor-addrow-bottom" href="#"';
$html[] = ' title="' . htmlspecialchars($lang->getLL('grid_addRow')) . '">';
$html[] = '<i class="fa fa-fw fa-plus"></i>';
$html[] = '</a>';
$html[] = '<a class="btn btn-default btn-sm t3js-grideditor-removerow-bottom" href="#"';
$html[] = ' title="' . htmlspecialchars($lang->getLL('grid_removeRow')) . '">';
$html[] = '<i class="fa fa-fw fa-minus"></i>';
$html[] = '</a>';
$html[] = '</div>';
$html[] = '</td>';
}
$html[] = '</tr>';
$html[] = '<tr>';
$html[] = '<td colspan="2">';
......@@ -169,7 +186,7 @@ class BackendLayoutWizardElement extends AbstractFormElement
$html[] = '</tr>';
$html[] = '</table>';
$html[] = '</div>';
if (!empty($fieldWizardHtml)) {
if (!$readOnly && !empty($fieldWizardHtml)) {
$html[] = '<div class="form-wizards-items-bottom">';
$html[] = $fieldWizardHtml;
$html[] = '</div>';
......
Supports Markdown
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