Skip to content

Commit a03f362

Browse files
georgringerbmack
authored andcommitted
[FEATURE] Associative array keys for TCA valuePicker items
The valuePicker configuration follows the syntax change used by the TCA items and uses array keys `label` and `value`, added with #99739. Resolves: #106092 Related: #99739 Releases: main Change-Id: Ieb8359fecde908b1cdcd766e6790b906f64beb99 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/88644 Reviewed-by: Benni Mack <benni@typo3.org> Reviewed-by: Stefan Bürk <stefan@buerk.tech> Tested-by: Benni Mack <benni@typo3.org> Tested-by: core-ci <typo3@b13.com> Tested-by: Stefan Bürk <stefan@buerk.tech>
1 parent db7f314 commit a03f362

File tree

21 files changed

+190
-54
lines changed

21 files changed

+190
-54
lines changed

typo3/sysext/backend/Classes/Configuration/TCA/UserFunctions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static function getAllSystemLocales(): array
9797
{
9898
$locales = [];
9999
foreach (Locales::getAllSystemLocales() as $locale) {
100-
$locales[] = [$locale, $locale];
100+
$locales[] = ['label' => $locale, 'value' => $locale];
101101
}
102102
return $locales;
103103
}

typo3/sysext/backend/Classes/Form/Element/ColorElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public function render(): array
144144
$valuePickerHtml[] = '<select class="form-select form-control-adapt">';
145145
$valuePickerHtml[] = '<option></option>';
146146
foreach ($config['valuePicker']['items'] as $item) {
147-
$valuePickerHtml[] = '<option value="' . htmlspecialchars($item[1]) . '">' . htmlspecialchars($languageService->sL($item[0])) . '</option>';
147+
$valuePickerHtml[] = '<option value="' . htmlspecialchars($item['value']) . '">' . htmlspecialchars($languageService->sL($item['label'])) . '</option>';
148148
}
149149
$valuePickerHtml[] = '</select>';
150150
$valuePickerHtml[] = '</typo3-formengine-valuepicker>';

typo3/sysext/backend/Classes/Form/Element/EmailElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function render(): array
156156
$valuePickerHtml[] = '<select ' . GeneralUtility::implodeAttributes($valuePickerAttributes, true) . '>';
157157
$valuePickerHtml[] = '<option></option>';
158158
foreach ($config['valuePicker']['items'] as $item) {
159-
$valuePickerHtml[] = '<option value="' . htmlspecialchars((string)$item[1]) . '">' . htmlspecialchars($languageService->sL($item[0])) . '</option>';
159+
$valuePickerHtml[] = '<option value="' . htmlspecialchars((string)$item['value']) . '">' . htmlspecialchars($languageService->sL($item['label'])) . '</option>';
160160
}
161161
$valuePickerHtml[] = '</select>';
162162
$valuePickerHtml[] = '</typo3-formengine-valuepicker>';

typo3/sysext/backend/Classes/Form/Element/InputTextElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public function render(): array
194194
$valuePickerHtml[] = '<select ' . GeneralUtility::implodeAttributes($valuePickerAttributes, true) . '>';
195195
$valuePickerHtml[] = '<option></option>';
196196
foreach ($config['valuePicker']['items'] as $item) {
197-
$valuePickerHtml[] = '<option value="' . htmlspecialchars($item[1]) . '">' . htmlspecialchars($languageService->sL($item[0])) . '</option>';
197+
$valuePickerHtml[] = '<option value="' . htmlspecialchars($item['value']) . '">' . htmlspecialchars($languageService->sL($item['label'])) . '</option>';
198198
}
199199
$valuePickerHtml[] = '</select>';
200200
$valuePickerHtml[] = '</typo3-formengine-valuepicker>';

typo3/sysext/backend/Classes/Form/Element/NumberElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function render(): array
165165
$valuePickerHtml[] = '<select ' . GeneralUtility::implodeAttributes($valuePickerAttributes, true) . '>';
166166
$valuePickerHtml[] = '<option></option>';
167167
foreach ($config['valuePicker']['items'] as $item) {
168-
$valuePickerHtml[] = '<option value="' . htmlspecialchars((string)$item[1]) . '">' . htmlspecialchars($languageService->sL($item[0])) . '</option>';
168+
$valuePickerHtml[] = '<option value="' . htmlspecialchars((string)$item['value']) . '">' . htmlspecialchars($languageService->sL($item['label'])) . '</option>';
169169
}
170170
$valuePickerHtml[] = '</select>';
171171
$valuePickerHtml[] = '</typo3-formengine-valuepicker>';

typo3/sysext/backend/Classes/Form/Element/TextElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public function render(): array
206206
$valuePickerHtml[] = '<select ' . GeneralUtility::implodeAttributes($valuePickerAttributes, true) . '>';
207207
$valuePickerHtml[] = '<option></option>';
208208
foreach ($config['valuePicker']['items'] as $item) {
209-
$valuePickerHtml[] = '<option value="' . htmlspecialchars($item[1]) . '">' . htmlspecialchars($languageService->sL($item[0])) . '</option>';
209+
$valuePickerHtml[] = '<option value="' . htmlspecialchars($item['value']) . '">' . htmlspecialchars($languageService->sL($item['label'])) . '</option>';
210210
}
211211
$valuePickerHtml[] = '</select>';
212212
$valuePickerHtml[] = '</typo3-formengine-valuepicker>';

typo3/sysext/backend/Configuration/SiteConfiguration/site_base_variant.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
'eval' => 'trim',
3131
'valuePicker' => [
3232
'items' => [
33-
[ 'LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_base_variant.condition.applicationContext', 'applicationContext == "Production"'],
34-
[ 'LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_base_variant.condition.environmentVariable', 'getenv("mycontext") == "production"'],
33+
[ 'label' => 'LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_base_variant.condition.applicationContext', 'value' => 'applicationContext == "Production"'],
34+
[ 'label' => 'LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_base_variant.condition.environmentVariable', 'value' => 'getenv("mycontext") == "production"'],
3535
],
3636
],
3737
'placeholder' => 'LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_base_variant.condition.placeholder',

typo3/sysext/backend/Configuration/SiteConfiguration/site_errorhandling.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
'valuePicker' => [
3232
'mode' => '',
3333
'items' => [
34-
['LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_errorhandling.errorCode.404', '404'],
35-
['LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_errorhandling.errorCode.403', '403'],
36-
['LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_errorhandling.errorCode.500', '500'],
37-
['LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_errorhandling.errorCode.503', '503'],
38-
['LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_errorhandling.errorCode.0', '0'],
34+
['label' => 'LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_errorhandling.errorCode.404', 'value' => '404'],
35+
['label' => 'LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_errorhandling.errorCode.403', 'value' => '403'],
36+
['label' => 'LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_errorhandling.errorCode.500', 'value' => '500'],
37+
['label' => 'LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_errorhandling.errorCode.503', 'value' => '503'],
38+
['label' => 'LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_errorhandling.errorCode.0', 'value' => '0'],
3939
],
4040
],
4141
],

typo3/sysext/backend/Configuration/SiteConfiguration/site_route.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
'placeholder' => 'LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_route.route.placeholder',
2424
'valuePicker' => [
2525
'items' => [
26-
['LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_route.route.example1', 'robots.txt'],
26+
['label' => 'LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_route.route.example1', 'value' => 'robots.txt'],
2727
],
2828
],
2929
],
@@ -49,7 +49,7 @@
4949
'required' => true,
5050
'valuePicker' => [
5151
'items' => [
52-
['LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_route.staticText.example1', 'User-agent: *
52+
['label' => 'LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_route.staticText.example1', 'value' => 'User-agent: *
5353
Disallow: /typo3/
5454
Disallow: /typo3_src/
5555
Disallow: /fileadmin/user_upload/_temp_/importexport
@@ -76,7 +76,7 @@
7676
'required' => true,
7777
'valuePicker' => [
7878
'items' => [
79-
['LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_route.asset.example', 'EXT:backend/Resources/Public/Icons/favicon.ico'],
79+
['label' => 'LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_route.asset.example', 'value' => 'EXT:backend/Resources/Public/Icons/favicon.ico'],
8080
],
8181
],
8282
],

typo3/sysext/core/Classes/Configuration/Tca/TcaMigration.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public function migrate(array $tca): array
8585
$tca = $this->removeFalRelatedOptionsFromTypeInline($tca);
8686
$tca = $this->removePassContentFromTypeNone($tca);
8787
$tca = $this->migrateItemsToAssociativeArray($tca);
88+
$tca = $this->migrateItemsOfValuePickerToAssociativeArray($tca);
8889
$tca = $this->removeMmInsertFields($tca);
8990
$tca = $this->removeMmHasUidField($tca);
9091
$tca = $this->migrateT3EditorToCodeEditor($tca);
@@ -1436,6 +1437,58 @@ protected function migrateItemsToAssociativeArray(array $tca): array
14361437
return $tca;
14371438
}
14381439

1440+
/**
1441+
* Converts the item list of valuePicker to an associated array.
1442+
*
1443+
* // From:
1444+
* [
1445+
* 0 => 'A label',
1446+
* 1 => 'value',
1447+
* ]
1448+
*
1449+
* // To:
1450+
* [
1451+
* 'label' => 'A label',
1452+
* 'value' => 'value',
1453+
* ]
1454+
*/
1455+
protected function migrateItemsOfValuePickerToAssociativeArray(array $tca): array
1456+
{
1457+
foreach ($tca as $table => $tableDefinition) {
1458+
if (!isset($tableDefinition['columns']) || !is_array($tableDefinition['columns'] ?? false)) {
1459+
continue;
1460+
}
1461+
foreach ($tableDefinition['columns'] as $fieldName => $fieldConfig) {
1462+
if (is_array($fieldConfig['config']['valuePicker']['items'] ?? false)) {
1463+
$hasLegacyItemConfiguration = false;
1464+
$items = $fieldConfig['config']['valuePicker']['items'];
1465+
foreach ($items as $key => $item) {
1466+
if (!is_array($item)) {
1467+
continue;
1468+
}
1469+
if (array_key_exists(0, $item)) {
1470+
$hasLegacyItemConfiguration = true;
1471+
$items[$key]['label'] = $item[0];
1472+
unset($items[$key][0]);
1473+
}
1474+
if (array_key_exists(1, $item)) {
1475+
$hasLegacyItemConfiguration = true;
1476+
$items[$key]['value'] = $item[1];
1477+
unset($items[$key][1]);
1478+
}
1479+
}
1480+
if ($hasLegacyItemConfiguration) {
1481+
$tca[$table]['columns'][$fieldName]['config']['valuePicker']['items'] = $items;
1482+
$this->messages[] = 'The TCA field \'' . $fieldName . '\' of table \'' . $table . '\' uses '
1483+
. 'the legacy way of defining \'items\' for the \'valuePicker\'. Please switch to associated array keys: '
1484+
. 'label, value.';
1485+
}
1486+
}
1487+
}
1488+
}
1489+
return $tca;
1490+
}
1491+
14391492
protected function removeMmInsertFields(array $tca): array
14401493
{
14411494
foreach ($tca as $table => $tableDefinition) {

0 commit comments

Comments
 (0)