From e6a2c2f6896255c997f47f0e310146291b3cd0b4 Mon Sep 17 00:00:00 2001 From: Oliver Bartsch <bo@cedev.de> Date: Thu, 22 Aug 2024 11:31:58 +0200 Subject: [PATCH] [BUGFIX] Migrate allowLanguageSynchronization in columnsOverrides Because the Localization\State does currently not support columnsOverrides, the localization state selector wizard throws an exception when setting allowLanguageSynchronization via columnsOverrides. This is now mitigated by removing the non working option from TCA via TcaMigration and informing the integrator about it. Additionally is the Localization\State checked in the wizard and an early return is done to prevent null pointer exceptions. Resolves: #104693 Resolves: #104403 Releases: main, 12.4 Change-Id: Ice719b2b198a6bc26abf0866ecae6c11da20cbea Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/85721 Tested-by: Jochen Roth <rothjochen@gmail.com> Reviewed-by: Nikita Hovratov <nikita.h@live.de> Reviewed-by: Oliver Bartsch <bo@cedev.de> Tested-by: Oliver Bartsch <bo@cedev.de> Reviewed-by: Oliver Hader <oliver.hader@typo3.org> Reviewed-by: Jochen Roth <rothjochen@gmail.com> Tested-by: Oliver Hader <oliver.hader@typo3.org> Tested-by: core-ci <typo3@b13.com> --- .../FieldWizard/LocalizationStateSelector.php | 14 ++-- .../Configuration/Tca/TcaMigration.php | 26 +++++++ ...uageSynchronizationViaColumnsOverrides.rst | 53 +++++++++++++ .../Configuration/Tca/TcaMigrationTest.php | 75 +++++++++++++++++++ 4 files changed, 162 insertions(+), 6 deletions(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/12.4.x/Important-104693-SettingAllowLanguageSynchronizationViaColumnsOverrides.rst diff --git a/typo3/sysext/backend/Classes/Form/FieldWizard/LocalizationStateSelector.php b/typo3/sysext/backend/Classes/Form/FieldWizard/LocalizationStateSelector.php index ce3e238f83be..8761ae062d3d 100644 --- a/typo3/sysext/backend/Classes/Form/FieldWizard/LocalizationStateSelector.php +++ b/typo3/sysext/backend/Classes/Form/FieldWizard/LocalizationStateSelector.php @@ -39,8 +39,15 @@ class LocalizationStateSelector extends AbstractNode $fieldName = $this->data['fieldName']; $fieldId = StringUtility::getUniqueId('formengine-localization-state-selector-'); $l10nStateFieldName = 'l10n_state'; + + $localizationState = State::fromJSON( + $this->data['tableName'], + $this->data['databaseRow'][$l10nStateFieldName] ?? null + ); + if ( - !isset($this->data['defaultLanguageRow']) + $localizationState === null + || !isset($this->data['defaultLanguageRow']) || !isset($this->data['processedTca']['columns'][$fieldName]['config']['behaviour']['allowLanguageSynchronization']) || !$this->data['processedTca']['columns'][$fieldName]['config']['behaviour']['allowLanguageSynchronization'] ) { @@ -68,11 +75,6 @@ class LocalizationStateSelector extends AbstractNode $fieldValueInParentRow = (string)$this->data['defaultLanguageRow'][$fieldName]; } - $localizationState = State::fromJSON( - $this->data['tableName'], - $this->data['databaseRow'][$l10nStateFieldName] ?? null - ); - $fieldElementName = 'data[' . htmlspecialchars($this->data['tableName']) . ']' . '[' . htmlspecialchars((string)$this->data['databaseRow']['uid']) . ']' . '[' . htmlspecialchars($l10nStateFieldName) . ']' diff --git a/typo3/sysext/core/Classes/Configuration/Tca/TcaMigration.php b/typo3/sysext/core/Classes/Configuration/Tca/TcaMigration.php index 529f8e3d66b4..be89b7d73050 100644 --- a/typo3/sysext/core/Classes/Configuration/Tca/TcaMigration.php +++ b/typo3/sysext/core/Classes/Configuration/Tca/TcaMigration.php @@ -87,6 +87,7 @@ class TcaMigration $tca = $this->removeMmInsertFields($tca); $tca = $this->removeMmHasUidField($tca); $tca = $this->migrateT3EditorToCodeEditor($tca); + $tca = $this->removeAllowLanguageSynchronizationFromColumnsOverrides($tca); return $tca; } @@ -1472,4 +1473,29 @@ class TcaMigration } return $tca; } + + /** + * Setting "allowLanguageSynchronization" for columns via columnsOverride is currently not supported + * see Localization\State and therefore leads to an exception in the LocalizationStateSelector wizard. + * Therefore, the setting is removed for now and the integrator is informed accordingly. + */ + protected function removeAllowLanguageSynchronizationFromColumnsOverrides(array $tca): array + { + foreach ($tca as $table => $tableDefinition) { + if (!is_array($tableDefinition['types'] ?? false)) { + continue; + } + foreach ($tableDefinition['types'] ?? [] as $typeName => $typeConfig) { + foreach ($typeConfig['columnsOverrides'] ?? [] as $columnOverride => $columnOverrideConfig) { + if (isset($columnOverrideConfig['config']['behaviour']['allowLanguageSynchronization'])) { + unset($tca[$table]['types'][$typeName]['columnsOverrides'][$columnOverride]['config']['behaviour']['allowLanguageSynchronization']); + $this->messages[] = 'The TCA columns override of column \'' . $columnOverride . '\' for type \'' . $typeName . '\' ' + . 'of table \'' . $table . '\' sets \'[behaviour][allowLanguageSynchronization]\'. Setting ' + . 'this option in \'columnsOverrides\' is currently not supported. Please adjust your TCA accordingly.'; + } + } + } + } + return $tca; + } } diff --git a/typo3/sysext/core/Documentation/Changelog/12.4.x/Important-104693-SettingAllowLanguageSynchronizationViaColumnsOverrides.rst b/typo3/sysext/core/Documentation/Changelog/12.4.x/Important-104693-SettingAllowLanguageSynchronizationViaColumnsOverrides.rst new file mode 100644 index 000000000000..c1948065c739 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/12.4.x/Important-104693-SettingAllowLanguageSynchronizationViaColumnsOverrides.rst @@ -0,0 +1,53 @@ +.. include:: /Includes.rst.txt + +.. _important-104693-1725960199: + +============================================================================== +Important: #104693 - Setting allowLanguageSynchronization via columnsOverrides +============================================================================== + +See :issue:`104693` + +Description +=========== + +Setting the TCA option :php:`allowLanguageSynchronization` for a specific +column in a record type via :php:`columnsOverrides` is currently not supported +by TYPO3 and therefore might lead to exceptions in the corresponding field wizard +(:php:`LocalizationStateSelector`). To mitigate this, the option is now +automatically removed from the TCA configuration via a TCA migration. A +corresponding deprecation log entry is added to inform integrators about +the necessary code adjustments. + +Migration +========= + +Remove the :php:`allowLanguageSynchronization` option from :php:`columnsOverrides` +for now. + +.. code-block:: php + + // Before + 'types' => [ + 'text' => [ + 'showitem' => 'header', + 'columnsOverrides' => [ + 'header' => [ + 'config' => [ + 'behaviour' => [ + 'allowLanguageSynchronization' => true + ], + ], + ], + ], + ], + ], + + // After + 'types' => [ + 'text' => [ + 'showitem' => 'header', + ], + ], + +.. index:: Backend, TCA, ext:backend diff --git a/typo3/sysext/core/Tests/Unit/Configuration/Tca/TcaMigrationTest.php b/typo3/sysext/core/Tests/Unit/Configuration/Tca/TcaMigrationTest.php index 4fa832f0b628..2eec8ae4ead3 100644 --- a/typo3/sysext/core/Tests/Unit/Configuration/Tca/TcaMigrationTest.php +++ b/typo3/sysext/core/Tests/Unit/Configuration/Tca/TcaMigrationTest.php @@ -3523,4 +3523,79 @@ final class TcaMigrationTest extends UnitTestCase ]; self::assertSame($expected, (new TcaMigration())->migrate($input)); } + + #[Test] + public function removeAllowLanguageSynchronizationFromColumnsOverrides(): void + { + $input = [ + 'aTable' => [ + 'columns' => [ + 'aColumn' => [ + 'config' => [ + 'type' => 'text', + 'config' => [ + 'behaviour' => [ + 'allowLanguageSynchronization' => true, + ], + ], + ], + ], + 'bColumn' => [ + 'config' => [ + 'type' => 'text', + ], + ], + ], + 'types' => [ + 'aType' => [ + 'showitem' => 'bColumn', + 'columnsOverrides' => [ + 'bColumn' => [ + 'config' => [ + 'behaviour' => [ + 'allowLanguageSynchronization' => true, + ], + ], + ], + ], + ], + ], + ], + ]; + $expected = [ + 'aTable' => [ + 'columns' => [ + 'aColumn' => [ + 'config' => [ + 'type' => 'text', + 'config' => [ + 'behaviour' => [ + 'allowLanguageSynchronization' => true, + ], + ], + ], + ], + 'bColumn' => [ + 'config' => [ + 'type' => 'text', + ], + ], + ], + 'types' => [ + 'aType' => [ + 'showitem' => 'bColumn', + 'columnsOverrides' => [ + 'bColumn' => [ + 'config' => [ + 'behaviour' => [ + ], + ], + ], + ], + ], + ], + ], + ]; + self::assertSame($expected, (new TcaMigration())->migrate($input)); + } } -- GitLab