Commit e125ccaf authored by Georg Ringer's avatar Georg Ringer Committed by Richard Haeser
Browse files

[BUGFIX] Respect readOnly for inline relation

If a TCA field is set to readOnly=true and is using the type "inline",
all buttons are now hidden and the fields of the relation are set to
readOnly as well.

Resolves: #56060
Releases: master, 9.5
Change-Id: If2b1cb2be0591d765f40512aaf341a9c26a2f87f
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61490

Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Torben Hansen's avatarTorben Hansen <derhansen@gmail.com>
Tested-by: Richard Haeser's avatarRichard Haeser <richard@maxserv.com>
Reviewed-by: Torben Hansen's avatarTorben Hansen <derhansen@gmail.com>
Reviewed-by: Richard Haeser's avatarRichard Haeser <richard@maxserv.com>
parent 587d0695
......@@ -119,7 +119,7 @@ class InlineControlContainer extends AbstractContainer
$config = $parameterArray['fieldConf']['config'];
$foreign_table = $config['foreign_table'];
$isReadOnly = isset($config['readOnly']) && $config['readOnly'];
$language = 0;
$languageFieldName = $GLOBALS['TCA'][$table]['ctrl']['languageField'];
if (BackendUtility::isTableLocalizable($table)) {
......@@ -273,7 +273,7 @@ class InlineControlContainer extends AbstractContainer
}
// Define how to show the "Create new record" link - if there are more than maxitems, hide it
if ($numberOfFullLocalizedChildren >= $config['maxitems'] || ($uniqueMax > 0 && $numberOfFullLocalizedChildren >= $uniqueMax)) {
if ($isReadOnly || $numberOfFullLocalizedChildren >= $config['maxitems'] || ($uniqueMax > 0 && $numberOfFullLocalizedChildren >= $uniqueMax)) {
$config['inline']['inlineNewButtonStyle'] = 'display: none;';
$config['inline']['inlineNewRelationButtonStyle'] = 'display: none;';
$config['inline']['inlineOnlineMediaAddButtonStyle'] = 'display: none;';
......@@ -297,7 +297,7 @@ class InlineControlContainer extends AbstractContainer
}
// If it's required to select from possible child records (reusable children), add a selector box
if ($config['foreign_selector'] && $config['appearance']['showPossibleRecordsSelector'] !== false) {
if (!$isReadOnly && $config['foreign_selector'] && $config['appearance']['showPossibleRecordsSelector'] !== false) {
if ($config['selectorOrUniqueConfiguration']['config']['type'] === 'select') {
$selectorBox = $this->renderPossibleRecordsSelectorTypeSelect($config, $uniqueIds);
} else {
......@@ -337,7 +337,7 @@ class InlineControlContainer extends AbstractContainer
$html .= $fieldWizardHtml;
// Add the level links after all child records:
if ($config['appearance']['levelLinksPosition'] === 'both' || $config['appearance']['levelLinksPosition'] === 'bottom') {
if (!$isReadOnly && ($config['appearance']['levelLinksPosition'] === 'both' || $config['appearance']['levelLinksPosition'] === 'bottom')) {
$html .= $levelLinks . $localizationLinks;
}
if (is_array($config['customControls'])) {
......
......@@ -251,6 +251,13 @@ class InlineRecordContainer extends AbstractContainer
$childData = $data['combinationChild'];
$parentConfig = $data['inlineParentConfig'];
// If field is set to readOnly, set all fields of the relation to readOnly as well
if (isset($parentConfig['readOnly']) && $parentConfig['readOnly']) {
foreach ($childData['processedTca']['columns'] as $columnName => $columnConfiguration) {
$childData['processedTca']['columns'][$columnName]['config']['readOnly'] = true;
}
}
$resultArray = $this->initializeResultArray();
// Display Warning FlashMessage if it is not suppressed
......@@ -413,6 +420,7 @@ class InlineRecordContainer extends AbstractContainer
'locked' => '',
];
$isNewItem = strpos($rec['uid'], 'NEW') === 0;
$isParentReadOnly = isset($inlineConfig['readOnly']) && $inlineConfig['readOnly'];
$isParentExisting = MathUtility::canBeInterpretedAsInteger($data['inlineParentUid']);
$tcaTableCtrl = $GLOBALS['TCA'][$foreignTable]['ctrl'];
$tcaTableCols = $GLOBALS['TCA'][$foreignTable]['columns'];
......@@ -460,7 +468,7 @@ class InlineRecordContainer extends AbstractContainer
}
}
// If the table is NOT a read-only table, then show these links:
if (!$tcaTableCtrl['readOnly'] && !$data['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
if (!$isParentReadOnly && !$tcaTableCtrl['readOnly'] && !$data['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
// "New record after" link (ONLY if the records in the table are sorted by a "sortby"-row or if default values can depend on previous record):
if ($enabledControls['new'] && ($enableManualSorting || $tcaTableCtrl['useColumnsForDefaultValues'])) {
if (!$isPagesTable && $calcPerms & Permission::CONTENT_EDIT || $isPagesTable && $calcPerms & Permission::PAGE_NEW) {
......
......@@ -50,6 +50,13 @@ class TcaInlineConfiguration implements FormDataProviderInterface
$result = $this->addInlineSelectorAndUniqueConfiguration($result, $fieldName);
}
// If field is set to readOnly, set all fields of the relation to readOnly as well
if (isset($result['inlineParentConfig']) && isset($result['inlineParentConfig']['readOnly']) && $result['inlineParentConfig']['readOnly']) {
foreach ($result['processedTca']['columns'] as $columnName => $columnConfiguration) {
$result['processedTca']['columns'][$columnName]['config']['readOnly'] = true;
}
}
return $result;
}
......
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