776f0b2854cee65f4b9dda7594a3811a3c3e39ab
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Migrations / TcaMigration.php
1 <?php
2 namespace TYPO3\CMS\Core\Migrations;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Core\Utility\StringUtility;
19
20 /**
21 * Migrate TCA from old to new syntax. Used in bootstrap and Flex Form Data Structures.
22 *
23 * @internal Class and API may change any time.
24 */
25 class TcaMigration
26 {
27 /**
28 * Accumulate migration messages
29 *
30 * @var array
31 */
32 protected $messages = [];
33
34 /**
35 * Migrate old TCA to new TCA.
36 *
37 * See unit tests for details.
38 *
39 * @param array $tca
40 * @return array
41 */
42 public function migrate(array $tca)
43 {
44 $tca = $this->migrateT3editorWizardToRenderTypeT3editorIfNotEnabledByTypeConfig($tca);
45 $tca = $this->migrateSpecialConfigurationAndRemoveShowItemStylePointerConfig($tca);
46 $tca = $this->migrateT3editorWizardWithEnabledByTypeConfigToColumnsOverrides($tca);
47 $tca = $this->migrateShowItemAdditionalPaletteToOwnPalette($tca);
48 $tca = $this->migrateIconsForFormFieldWizardsToNewLocation($tca);
49 $tca = $this->migrateExtAndSysextPathToEXTPath($tca);
50 $tca = $this->migrateIconsInOptionTags($tca);
51 $tca = $this->migrateIconfileRelativePathOrFilenameOnlyToExtReference($tca);
52 $tca = $this->migrateSelectFieldRenderType($tca);
53 $tca = $this->migrateSelectFieldIconTable($tca);
54 $tca = $this->migrateElementBrowserWizardToLinkHandler($tca);
55 $tca = $this->migrateDefaultExtrasRteTransFormOptions($tca);
56 $tca = $this->migrateColorPickerWizardToRenderType($tca);
57 $tca = $this->migrateSelectTreeOptions($tca);
58 $tca = $this->migrateTSconfigSoftReferences($tca);
59 $tca = $this->migrateShowIfRteOption($tca);
60 // @todo: if showitem/defaultExtras wizards[xy] is migrated to columnsOverrides here, enableByTypeConfig could be dropped
61 return $tca;
62 }
63
64 /**
65 * Get messages of migrated fields. Can be used for deprecation messages after migrate() was called.
66 *
67 * @return array Migration messages
68 */
69 public function getMessages()
70 {
71 return $this->messages;
72 }
73
74 /**
75 * Migrate type=text field with t3editor wizard to renderType=t3editor without this wizard
76 *
77 * @param array $tca Incoming TCA
78 * @return array Migrated TCA
79 */
80 protected function migrateT3editorWizardToRenderTypeT3editorIfNotEnabledByTypeConfig(array $tca)
81 {
82 $newTca = $tca;
83 foreach ($tca as $table => $tableDefinition) {
84 if (!isset($tableDefinition['columns']) || !is_array($tableDefinition['columns'])) {
85 continue;
86 }
87 foreach ($tableDefinition['columns'] as $fieldName => $fieldConfig) {
88 if (
89 !empty($fieldConfig['config']['type']) // type is set
90 && trim($fieldConfig['config']['type']) === 'text' // to "text"
91 && isset($fieldConfig['config']['wizards'])
92 && is_array($fieldConfig['config']['wizards']) // and there are wizards
93 ) {
94 foreach ($fieldConfig['config']['wizards'] as $wizardName => $wizardConfig) {
95 if (
96 !empty($wizardConfig['userFunc']) // a userFunc is defined
97 && trim($wizardConfig['userFunc']) === 'TYPO3\\CMS\\T3editor\\FormWizard->main' // and set to FormWizard
98 && (
99 !isset($wizardConfig['enableByTypeConfig']) // and enableByTypeConfig is not set
100 || (isset($wizardConfig['enableByTypeConfig']) && !$wizardConfig['enableByTypeConfig']) // or set, but not enabled
101 )
102 ) {
103 // Set renderType from text to t3editor
104 $newTca[$table]['columns'][$fieldName]['config']['renderType'] = 't3editor';
105 // Unset this wizard definition
106 unset($newTca[$table]['columns'][$fieldName]['config']['wizards'][$wizardName]);
107 // Move format parameter
108 if (!empty($wizardConfig['params']['format'])) {
109 $newTca[$table]['columns'][$fieldName]['config']['format'] = $wizardConfig['params']['format'];
110 }
111 $this->messages[] = 'Migrated t3editor wizard in TCA of table "' . $table . '" field "' . $fieldName . '" to a renderType definition.';
112 }
113 }
114 // If no wizard is left after migration, unset the whole sub array
115 if (empty($newTca[$table]['columns'][$fieldName]['config']['wizards'])) {
116 unset($newTca[$table]['columns'][$fieldName]['config']['wizards']);
117 }
118 }
119 }
120 }
121 return $newTca;
122 }
123
124 /**
125 * Remove "style pointer", the 5th parameter from "types" "showitem" configuration.
126 * Move "specConf", 4th parameter from "tyes" "showitem" to "types" "columnsOverrides.
127 *
128 * @param array $tca Incoming TCA
129 * @return array Modified TCA
130 */
131 protected function migrateSpecialConfigurationAndRemoveShowItemStylePointerConfig(array $tca)
132 {
133 $newTca = $tca;
134 foreach ($tca as $table => $tableDefinition) {
135 if (!isset($tableDefinition['types']) || !is_array($tableDefinition['types'])) {
136 continue;
137 }
138 foreach ($tableDefinition['types'] as $typeName => $typeArray) {
139 if (!isset($typeArray['showitem']) || !is_string($typeArray['showitem']) || strpos($typeArray['showitem'], ';') === false) {
140 // Continue directly if no semicolon is found
141 continue;
142 }
143 $itemList = GeneralUtility::trimExplode(',', $typeArray['showitem'], true);
144 $newFieldStrings = [];
145 foreach ($itemList as $fieldString) {
146 $fieldString = rtrim($fieldString, ';');
147 // Unpack the field definition, migrate and remove as much as possible
148 // Keep empty parameters in trimExplode here (third parameter FALSE), so position is not changed
149 $fieldArray = GeneralUtility::trimExplode(';', $fieldString);
150 $fieldArray = [
151 'fieldName' => isset($fieldArray[0]) ? $fieldArray[0] : '',
152 'fieldLabel' => isset($fieldArray[1]) ? $fieldArray[1] : null,
153 'paletteName' => isset($fieldArray[2]) ? $fieldArray[2] : null,
154 'fieldExtra' => isset($fieldArray[3]) ? $fieldArray[3] : null,
155 ];
156 $fieldName = $fieldArray['fieldName'];
157 if (!empty($fieldArray['fieldExtra'])) {
158 // Move fieldExtra "specConf" to columnsOverrides "defaultExtras"
159 if (!isset($newTca[$table]['types'][$typeName]['columnsOverrides'])) {
160 $newTca[$table]['types'][$typeName]['columnsOverrides'] = [];
161 }
162 if (!isset($newTca[$table]['types'][$typeName]['columnsOverrides'][$fieldArray['fieldName']])) {
163 $newTca[$table]['types'][$typeName]['columnsOverrides'][$fieldArray['fieldName']] = [];
164 }
165 // Merge with given defaultExtras from columns.
166 // They will be the first part of the string, so if "specConf" from types changes the same settings,
167 // those will override settings from defaultExtras of columns
168 $newDefaultExtras = [];
169 if (!empty($tca[$table]['columns'][$fieldArray['fieldName']]['defaultExtras'])) {
170 $newDefaultExtras[] = $tca[$table]['columns'][$fieldArray['fieldName']]['defaultExtras'];
171 }
172 $newDefaultExtras[] = $fieldArray['fieldExtra'];
173 $newTca[$table]['types'][$typeName]['columnsOverrides'][$fieldArray['fieldName']]['defaultExtras'] = implode(':', $newDefaultExtras);
174 }
175 unset($fieldArray['fieldExtra']);
176 if (count($fieldArray) === 3 && empty($fieldArray['paletteName'])) {
177 unset($fieldArray['paletteName']);
178 }
179 if (count($fieldArray) === 2 && empty($fieldArray['fieldLabel'])) {
180 unset($fieldArray['fieldLabel']);
181 }
182 if (count($fieldArray) === 1 && empty($fieldArray['fieldName'])) {
183 // The field may vanish if nothing is left
184 unset($fieldArray['fieldName']);
185 }
186 $newFieldString = implode(';', $fieldArray);
187 if ($newFieldString !== $fieldString) {
188 $this->messages[] = 'Changed showitem string of TCA table "' . $table . '" type "' . $typeName . '" due to changed field "' . $fieldName . '".';
189 }
190 if (!empty($newFieldString)) {
191 $newFieldStrings[] = $newFieldString;
192 }
193 }
194 $newTca[$table]['types'][$typeName]['showitem'] = implode(',', $newFieldStrings);
195 }
196 }
197 return $newTca;
198 }
199
200 /**
201 * Migrate type=text field with t3editor wizard that is "enableByTypeConfig" to columnsOverrides
202 * with renderType=t3editor
203 *
204 * @param array $tca Incoming TCA
205 * @return array Migrated TCA
206 */
207 protected function migrateT3editorWizardWithEnabledByTypeConfigToColumnsOverrides(array $tca)
208 {
209 $newTca = $tca;
210 foreach ($tca as $table => $tableDefinition) {
211 if (!isset($tableDefinition['columns']) || !is_array($tableDefinition['columns'])) {
212 continue;
213 }
214 foreach ($tableDefinition['columns'] as $fieldName => $fieldConfig) {
215 if (
216 !empty($fieldConfig['config']['type']) // type is set
217 && trim($fieldConfig['config']['type']) === 'text' // to "text"
218 && isset($fieldConfig['config']['wizards'])
219 && is_array($fieldConfig['config']['wizards']) // and there are wizards
220 ) {
221 foreach ($fieldConfig['config']['wizards'] as $wizardName => $wizardConfig) {
222 if (
223 !empty($wizardConfig['userFunc']) // a userFunc is defined
224 && trim($wizardConfig['userFunc']) === 'TYPO3\CMS\T3editor\FormWizard->main' // and set to FormWizard
225 && !empty($wizardConfig['enableByTypeConfig']) // and enableByTypeConfig is enabled
226 ) {
227 // Remove this wizard
228 unset($newTca[$table]['columns'][$fieldName]['config']['wizards'][$wizardName]);
229 // Find configured types that use this wizard
230 if (!isset($tableDefinition['types']) || !is_array($tableDefinition['types'])) {
231 // No type definition at all ... continue directly
232 continue;
233 }
234 foreach ($tableDefinition['types'] as $typeName => $typeArray) {
235 if (
236 empty($typeArray['columnsOverrides'][$fieldName]['defaultExtras'])
237 || strpos($typeArray['columnsOverrides'][$fieldName]['defaultExtras'], $wizardName) === false
238 ) {
239 // Continue directly if this wizard is not enabled for given type
240 continue;
241 }
242 $defaultExtras = $typeArray['columnsOverrides'][$fieldName]['defaultExtras'];
243 $defaultExtrasArray = GeneralUtility::trimExplode(':', $defaultExtras, true);
244 $newDefaultExtrasArray = [];
245 foreach ($defaultExtrasArray as $fieldExtraField) {
246 // There might be multiple enabled wizards separated by | ... split them
247 if (substr($fieldExtraField, 0, 8) === 'wizards[') {
248 $enabledWizards = substr($fieldExtraField, 8, strlen($fieldExtraField) - 8); // Cut off "wizards[
249 $enabledWizards = substr($enabledWizards, 0, strlen($enabledWizards) - 1);
250 $enabledWizardsArray = GeneralUtility::trimExplode('|', $enabledWizards, true);
251 $newEnabledWizardsArray = [];
252 foreach ($enabledWizardsArray as $enabledWizardName) {
253 if ($enabledWizardName === $wizardName) {
254 // Found a columnsOverrides configuration that has this wizard enabled
255 // Force renderType = t3editor
256 $newTca[$table]['types'][$typeName]['columnsOverrides'][$fieldName]['config']['renderType'] = 't3editor';
257 // Transfer format option if given
258 if (!empty($wizardConfig['params']['format'])) {
259 $newTca[$table]['types'][$typeName]['columnsOverrides'][$fieldName]['config']['format'] = $wizardConfig['params']['format'];
260 }
261 $this->messages[] = 'Migrated t3editor wizard in TCA of table "' . $table . '" field "' . $fieldName
262 . '" to a renderType definition with columnsOverrides in type "' . $typeName . '".';
263 } else {
264 // Some other enabled wizard
265 $newEnabledWizardsArray[] = $enabledWizardName;
266 }
267 }
268 if (!empty($newEnabledWizardsArray)) {
269 $newDefaultExtrasArray[] = 'wizards[' . implode('|', $newEnabledWizardsArray) . ']';
270 }
271 } else {
272 $newDefaultExtrasArray[] = $fieldExtraField;
273 }
274 }
275 if (!empty($newDefaultExtrasArray)) {
276 $newTca[$table]['types'][$typeName]['columnsOverrides'][$fieldName]['defaultExtras'] = implode(':', $newDefaultExtrasArray);
277 } else {
278 unset($newTca[$table]['types'][$typeName]['columnsOverrides'][$fieldName]['defaultExtras']);
279 }
280 }
281 }
282 }
283 // If no wizard is left after migration, unset the whole sub array
284 if (empty($newTca[$table]['columns'][$fieldName]['config']['wizards'])) {
285 unset($newTca[$table]['columns'][$fieldName]['config']['wizards']);
286 }
287 }
288 }
289 }
290 return $newTca;
291 }
292
293 /**
294 * Migrate types showitem 'aField;aLabel;aPalette' to 'afield;aLabel, --palette--;;aPalette'
295 *
296 * Old showitem can have a syntax like:
297 * fieldName;aLabel;aPalette
298 * This way, the palette with name "aPalette" is rendered after fieldName.
299 * The migration parses this to a syntax like:
300 * fieldName;aLabel, --palette--;;paletteName
301 *
302 * @param array $tca Incoming TCA
303 * @return array Migrated TCA
304 */
305 protected function migrateShowItemAdditionalPaletteToOwnPalette(array $tca)
306 {
307 $newTca = $tca;
308 foreach ($tca as $table => $tableDefinition) {
309 if (!isset($tableDefinition['types']) || !is_array($tableDefinition['types'])) {
310 continue;
311 }
312 foreach ($tableDefinition['types'] as $typeName => $typeArray) {
313 if (
314 !isset($typeArray['showitem'])
315 || !is_string($typeArray['showitem'])
316 || strpos($typeArray['showitem'], ';') === false // no field parameters
317 ) {
318 continue;
319 }
320 $itemList = GeneralUtility::trimExplode(',', $typeArray['showitem'], true);
321 $newFieldStrings = [];
322 foreach ($itemList as $fieldString) {
323 $fieldArray = GeneralUtility::trimExplode(';', $fieldString);
324 $fieldArray = [
325 'fieldName' => isset($fieldArray[0]) ? $fieldArray[0] : '',
326 'fieldLabel' => isset($fieldArray[1]) ? $fieldArray[1] : null,
327 'paletteName' => isset($fieldArray[2]) ? $fieldArray[2] : null,
328 ];
329 if ($fieldArray['fieldName'] !== '--palette--' && $fieldArray['paletteName'] !== null) {
330 if ($fieldArray['fieldLabel']) {
331 $fieldString = $fieldArray['fieldName'] . ';' . $fieldArray['fieldLabel'];
332 } else {
333 $fieldString = $fieldArray['fieldName'];
334 }
335 $paletteString = '--palette--;;' . $fieldArray['paletteName'];
336 $this->messages[] = 'Migrated TCA table "' . $table . '" showitem field of type "' . $typeName . '": Moved additional palette'
337 . ' with name "' . $fieldArray['paletteName'] . '" as 3rd argument of field "' . $fieldArray['fieldName']
338 . '" to an own palette. The result of this part is: "' . $fieldString . ', ' . $paletteString . '"';
339 $newFieldStrings[] = $fieldString;
340 $newFieldStrings[] = $paletteString;
341 } else {
342 $newFieldStrings[] = $fieldString;
343 }
344 }
345 $newTca[$table]['types'][$typeName]['showitem'] = implode(',', $newFieldStrings);
346 }
347 }
348 return $newTca;
349 }
350
351 /**
352 * Migrate core icons for form field wizard to new location
353 *
354 * @param array $tca Incoming TCA
355 * @return array Migrated TCA
356 */
357 protected function migrateIconsForFormFieldWizardsToNewLocation(array $tca)
358 {
359 $newTca = $tca;
360
361 $newFileLocations = [
362 'add.gif' => 'actions-add',
363 'link_popup.gif' => 'actions-wizard-link',
364 'wizard_rte2.gif' => 'actions-wizard-rte',
365 'wizard_table.gif' => 'content-table',
366 'edit2.gif' => 'actions-open',
367 'list.gif' => 'actions-system-list-open',
368 'wizard_forms.gif' => 'EXT:backend/Resources/Public/Images/FormFieldWizard/wizard_forms.gif',
369 'EXT:backend/Resources/Public/Images/FormFieldWizard/wizard_add.gif' => 'actions-add',
370 'EXT:backend/Resources/Public/Images/FormFieldWizard/wizard_table.gif' => 'content-table',
371 'EXT:backend/Resources/Public/Images/FormFieldWizard/wizard_edit.gif' => 'actions-open',
372 'EXT:backend/Resources/Public/Images/FormFieldWizard/wizard_list.gif' => 'actions-system-list-open',
373 'EXT:backend/Resources/Public/Images/FormFieldWizard/wizard_link.gif' => 'actions-wizard-link',
374 'EXT:backend/Resources/Public/Images/FormFieldWizard/wizard_rte.gif' => 'actions-wizard-rte'
375 ];
376 $oldFileNames = array_keys($newFileLocations);
377
378 foreach ($tca as $table => $tableDefinition) {
379 if (!isset($tableDefinition['columns']) || !is_array($tableDefinition['columns'])) {
380 continue;
381 }
382 foreach ($tableDefinition['columns'] as $fieldName => $fieldConfig) {
383 if (
384 isset($fieldConfig['config']['wizards'])
385 && is_array($fieldConfig['config']['wizards']) // and there are wizards
386 ) {
387 foreach ($fieldConfig['config']['wizards'] as $wizardName => $wizardConfig) {
388 if (!is_array($wizardConfig)) {
389 continue;
390 }
391
392 foreach ($wizardConfig as $option => $value) {
393 if ($option === 'icon' && in_array($value, $oldFileNames, true)) {
394 $newTca[$table]['columns'][$fieldName]['config']['wizards'][$wizardName]['icon'] = $newFileLocations[$value];
395 $this->messages[] = 'Migrated icon path of wizard "' . $wizardName . '" in field "' . $fieldName . '" from TCA table "' . $table . '". New path is: ' . $newFileLocations[$value];
396 }
397 }
398 }
399 }
400 }
401 }
402
403 return $newTca;
404 }
405
406 /**
407 * Migrate file reference which starts with ext/ or sysext/ to EXT:
408 *
409 * @param array $tca Incoming TCA
410 * @return array Migrated TCA
411 */
412 protected function migrateExtAndSysextPathToEXTPath(array $tca)
413 {
414 foreach ($tca as $table => &$tableDefinition) {
415 if (!isset($tableDefinition['columns']) || !is_array($tableDefinition['columns'])) {
416 continue;
417 }
418 foreach ($tableDefinition['columns'] as $fieldName => &$fieldConfig) {
419 if (
420 !empty($fieldConfig['config']['type']) // type is set
421 && trim($fieldConfig['config']['type']) === 'select' // to "select"
422 && isset($fieldConfig['config']['items'])
423 && is_array($fieldConfig['config']['items']) // and there are items
424 ) {
425 foreach ($fieldConfig['config']['items'] as &$itemConfig) {
426 // more then two values? then the third entry is the image path
427 if (!empty($itemConfig[2])) {
428 $tcaPath = implode('.', [$table, 'columns', $fieldName, 'config', 'items']);
429 $pathParts = GeneralUtility::trimExplode('/', $itemConfig[2]);
430 // remove first element (ext or sysext)
431 array_shift($pathParts);
432 $path = implode('/', $pathParts);
433 // If the path starts with ext/ or sysext/ migrate it
434 if (
435 StringUtility::beginsWith($itemConfig[2], 'ext/')
436 || StringUtility::beginsWith($itemConfig[2], 'sysext/')
437 ) {
438 $this->messages[] = '[' . $tcaPath . '] ext/ or sysext/ within the path (' . $path . ') in items array is deprecated, use EXT: reference';
439 $itemConfig[2] = 'EXT:' . $path;
440 } elseif (StringUtility::beginsWith($itemConfig[2], 'i/')) {
441 $this->messages[] = '[' . $tcaPath . '] i/ within the path (' . $path . ') in items array is deprecated, use EXT: reference';
442 $itemConfig[2] = 'EXT:t3skin/icons/gfx/' . $itemConfig[2];
443 }
444 }
445 }
446 }
447 }
448 }
449 return $tca;
450 }
451
452 /**
453 * Migrate "iconsInOptionTags" for "select" TCA fields
454 *
455 * @param array $tca Incoming TCA
456 * @return array Migrated TCA
457 */
458 protected function migrateIconsInOptionTags(array $tca)
459 {
460 $newTca = $tca;
461
462 foreach ($newTca as $table => &$tableDefinition) {
463 if (!isset($tableDefinition['columns']) || !is_array($tableDefinition['columns'])) {
464 continue;
465 }
466 foreach ($tableDefinition['columns'] as $fieldName => &$fieldConfig) {
467 if (isset($fieldConfig['config']['iconsInOptionTags'])) {
468 unset($fieldConfig['config']['iconsInOptionTags']);
469 $this->messages[] = 'Configuration option "iconsInOptionTags" was removed from field "' . $fieldName . '" in TCA table "' . $table . '"';
470 }
471 }
472 }
473
474 return $newTca;
475 }
476
477 /**
478 * Migrate "iconfile" references which starts with ../ to EXT: and consisting of filename only to absolute paths in EXT:t3skin
479 *
480 * @param array $tca Incoming TCA
481 * @return array Migrated TCA
482 */
483 protected function migrateIconfileRelativePathOrFilenameOnlyToExtReference(array $tca)
484 {
485 foreach ($tca as $table => &$tableDefinition) {
486 if (!isset($tableDefinition['ctrl']) || !is_array($tableDefinition['ctrl'])) {
487 continue;
488 }
489 if (!isset($tableDefinition['ctrl']['iconfile'])) {
490 continue;
491 }
492 if (StringUtility::beginsWith($tableDefinition['ctrl']['iconfile'], '../typo3conf/ext/')) {
493 $tableDefinition['ctrl']['iconfile'] = str_replace('../typo3conf/ext/', 'EXT:', $tableDefinition['ctrl']['iconfile']);
494 $tcaPath = implode('.', [$table, 'ctrl', 'iconfile']);
495 $this->messages[] = '[' . $tcaPath . '] relative path to ../typo3conf/ext/ is deprecated, use EXT: instead';
496 } elseif (strpos($tableDefinition['ctrl']['iconfile'], '/') === false) {
497 $tableDefinition['ctrl']['iconfile'] = 'EXT:t3skin/icons/gfx/i/' . $tableDefinition['ctrl']['iconfile'];
498 $tcaPath = implode('.', [$table, 'ctrl', 'iconfile']);
499 $this->messages[] = '[' . $tcaPath . '] filename only is deprecated, use EXT: or absolute reference instead';
500 }
501 }
502 return $tca;
503 }
504
505 /**
506 * Migrate "type=select" with "renderMode=[tree|singlebox|checkbox]" to "renderType=[selectTree|selectSingleBox|selectCheckBox]".
507 * This migration also take care of "maxitems" settings and set "renderType=[selectSingle|selectMultipleSideBySide]" if no other
508 * renderType is already set.
509 *
510 * @param array $tca
511 * @return array
512 */
513 public function migrateSelectFieldRenderType(array $tca)
514 {
515 $newTca = $tca;
516
517 foreach ($newTca as $table => &$tableDefinition) {
518 if (empty($tableDefinition['columns'])) {
519 continue;
520 }
521
522 foreach ($tableDefinition['columns'] as $columnName => &$columnDefinition) {
523 // Only handle select fields.
524 if (empty($columnDefinition['config']['type']) || $columnDefinition['config']['type'] !== 'select') {
525 continue;
526 }
527 // Do not handle field where the render type is set.
528 if (!empty($columnDefinition['config']['renderType'])) {
529 continue;
530 }
531
532 $tableColumnInfo = 'table "' . $table . '" and column "' . $columnName . '"';
533 $this->messages[] = 'Using select fields without the "renderType" setting is deprecated in ' . $tableColumnInfo;
534
535 $columnConfig = &$columnDefinition['config'];
536 if (!empty($columnConfig['renderMode'])) {
537 $this->messages[] = 'The "renderMode" setting for select fields is deprecated. Please use "renderType" instead in ' . $tableColumnInfo;
538 switch ($columnConfig['renderMode']) {
539 case 'tree':
540 $columnConfig['renderType'] = 'selectTree';
541 break;
542 case 'singlebox':
543 $columnConfig['renderType'] = 'selectSingleBox';
544 break;
545 case 'checkbox':
546 $columnConfig['renderType'] = 'selectCheckBox';
547 break;
548 default:
549 $this->messages[] = 'The render mode ' . $columnConfig['renderMode'] . ' is invalid for the select field in ' . $tableColumnInfo;
550 }
551 continue;
552 }
553
554 $maxItems = !empty($columnConfig['maxitems']) ? (int)$columnConfig['maxitems'] : 1;
555 if ($maxItems <= 1) {
556 $columnConfig['renderType'] = 'selectSingle';
557 } else {
558 $columnConfig['renderType'] = 'selectMultipleSideBySide';
559 }
560 }
561 }
562
563 return $newTca;
564 }
565
566 /**
567 * Migrate the visibility of the icon table for fields with "renderType=selectSingle"
568 *
569 * @param array $tca
570 * @return array Migrated TCA
571 */
572 public function migrateSelectFieldIconTable(array $tca)
573 {
574 foreach ($tca as $table => &$tableDefinition) {
575 if (!isset($tableDefinition['columns']) || !is_array($tableDefinition['columns'])) {
576 continue;
577 }
578 foreach ($tableDefinition['columns'] as $fieldName => &$fieldConfig) {
579 if (empty($fieldConfig['config']['renderType']) || $fieldConfig['config']['renderType'] !== 'selectSingle') {
580 continue;
581 }
582 if (!empty($fieldConfig['config']['selicon_cols'])) {
583 // selicon_cols without showIconTable true does not make sense, so set it to true here if not already defined
584 if (!array_key_exists('showIconTable', $fieldConfig['config'])) {
585 $this->messages[] = 'The "showIconTable" setting is missing for table "' . $table . '" and field "' . $fieldName . '"';
586 $fieldConfig['config']['showIconTable'] = true;
587 }
588 }
589 if (array_key_exists('noIconsBelowSelect', $fieldConfig['config'])) {
590 $this->messages[] = 'The "noIconsBelowSelect" setting for select fields was removed. Please define the setting "showIconTable" for table "' . $table . '" and field "' . $fieldName . '"';
591 if (!$fieldConfig['config']['noIconsBelowSelect']) {
592 // If old setting was explicitly false, enable icon table if not defined yet
593 if (!array_key_exists('showIconTable', $fieldConfig['config'])) {
594 $fieldConfig['config']['showIconTable'] = true;
595 }
596 }
597 unset($fieldConfig['config']['noIconsBelowSelect']);
598 }
599 if (array_key_exists('suppress_icons', $fieldConfig['config'])) {
600 $this->messages[] = 'The "suppress_icons" setting for select fields was removed. Please define the setting "showIconTable" for table "' . $table . '" and field "' . $fieldName . '"';
601 unset($fieldConfig['config']['suppress_icons']);
602 }
603 if (array_key_exists('foreign_table_loadIcons', $fieldConfig['config'])) {
604 $this->messages[] = 'The "foreign_table_loadIcons" setting for select fields was removed. Please define the setting "showIconTable" for table "' . $table . '" and field "' . $fieldName . '"';
605 unset($fieldConfig['config']['foreign_table_loadIcons']);
606 }
607 }
608 }
609 return $tca;
610 }
611
612 /**
613 * Migrate wizard "wizard_element_browser" used in mode "wizard" to use the "wizard_link" instead
614 *
615 * @param array $tca
616 * @return array Migrated TCA
617 */
618 protected function migrateElementBrowserWizardToLinkHandler(array $tca)
619 {
620 foreach ($tca as $table => &$tableDefinition) {
621 if (!isset($tableDefinition['columns']) || !is_array($tableDefinition['columns'])) {
622 continue;
623 }
624 foreach ($tableDefinition['columns'] as $fieldName => &$fieldConfig) {
625 if (
626 isset($fieldConfig['config']['wizards']['link']['module']['name']) && $fieldConfig['config']['wizards']['link']['module']['name'] === 'wizard_element_browser'
627 && isset($fieldConfig['config']['wizards']['link']['module']['urlParameters']['mode']) && $fieldConfig['config']['wizards']['link']['module']['urlParameters']['mode'] === 'wizard'
628 ) {
629 $fieldConfig['config']['wizards']['link']['module']['name'] = 'wizard_link';
630 unset($fieldConfig['config']['wizards']['link']['module']['urlParameters']['mode']);
631 if (empty($fieldConfig['config']['wizards']['link']['module']['urlParameters'])) {
632 unset($fieldConfig['config']['wizards']['link']['module']['urlParameters']);
633 }
634 $this->messages[] = 'Reference to "wizard_element_browser" was migrated to new "wizard_link" for field "' . $fieldName . '" in TCA table "' . $table . '"';
635 }
636 }
637 }
638 return $tca;
639 }
640
641 /**
642 * Migrate defaultExtras "richtext:rte_transform[mode=ts_css]" and similar stuff like
643 * "richtext:rte_transform[mode=ts_css]" to "richtext:rte_transform"
644 *
645 * @param array $tca
646 * @return array Migrated TCA
647 */
648 protected function migrateDefaultExtrasRteTransFormOptions(array $tca)
649 {
650 foreach ($tca as $table => &$tableDefinition) {
651 if (!isset($tableDefinition['columns']) || !is_array($tableDefinition['columns'])) {
652 continue;
653 }
654 foreach ($tableDefinition['columns'] as $fieldName => &$fieldConfig) {
655 if (isset($fieldConfig['defaultExtras'])) {
656 $oldValue = $fieldConfig['defaultExtras'];
657 $fieldConfig['defaultExtras'] = preg_replace(
658 '/richtext(\[([^\]]*)\])*:rte_transform(\[([^\]]*)\])/',
659 'richtext${1}:rte_transform',
660 $fieldConfig['defaultExtras'],
661 -1,
662 $replacementCount
663 );
664 if ($replacementCount) {
665 $this->messages[] = 'rte_transform options are deprecated. String "' . $oldValue . '" in TCA'
666 . ' ' . $table . '[\'columns\'][\'' . $fieldName . '\'][\'defaultExtras\'] was changed to "'
667 . $fieldConfig['defaultExtras'] . '"';
668 }
669 }
670 }
671 }
672
673 foreach ($tca as $table => &$tableDefinition) {
674 if (!isset($tableDefinition['types']) || !is_array($tableDefinition['types'])) {
675 continue;
676 }
677 foreach ($tableDefinition['types'] as $typeName => &$typeArray) {
678 if (!isset($typeArray['columnsOverrides']) || !is_array($typeArray['columnsOverrides'])) {
679 continue;
680 }
681 foreach ($typeArray['columnsOverrides'] as $fieldName => &$fieldConfig) {
682 if (isset($fieldConfig['defaultExtras'])) {
683 $oldValue = $fieldConfig['defaultExtras'];
684 $fieldConfig['defaultExtras'] = preg_replace(
685 '/richtext(\[([^\]]*)\])*:rte_transform(\[([^\]]*)\])/',
686 'richtext${1}:rte_transform',
687 $fieldConfig['defaultExtras'],
688 -1,
689 $replacementCount
690 );
691 if ($replacementCount) {
692 $this->messages[] = 'rte_transform options are deprecated. String "'
693 . $oldValue . '" in TCA'
694 . ' ' . $table . '[\'types\'][\'' . $typeName
695 . '\'][\'columnsOverrides\'][\'' . $fieldName
696 . '\'][\'defaultExtras\']' .
697 ' was changed to "' . $fieldConfig['defaultExtras'] . '"';
698 }
699 }
700 }
701 }
702 }
703
704 return $tca;
705 }
706
707 /**
708 * Migrates fields having a colorpicker wizard to a color field
709 *
710 * @param array $tca Incoming TCA
711 * @return array Migrated TCA
712 */
713 protected function migrateColorPickerWizardToRenderType(array $tca)
714 {
715 foreach ($tca as $table => &$tableDefinition) {
716 if (!isset($tableDefinition['columns']) || !is_array($tableDefinition['columns'])) {
717 continue;
718 }
719 foreach ($tableDefinition['columns'] as $fieldName => &$fieldConfig) {
720 if (isset($fieldConfig['config'])) {
721 if (isset($fieldConfig['config']['wizards'])) {
722 foreach ($fieldConfig['config']['wizards'] as $wizardName => $wizard) {
723 if (isset($wizard['type']) && ($wizard['type'] === 'colorbox')) {
724 unset($fieldConfig['config']['wizards'][$wizardName]);
725 if (empty($fieldConfig['config']['wizards'])) {
726 unset($fieldConfig['config']['wizards']);
727 }
728 $fieldConfig['config']['renderType'] = 'colorpicker';
729
730 $this->messages[] = 'The color-picker wizard using \'colorbox\' is deprecated'
731 . ' in TCA ' . $table . '[\'columns\'][\'' . $fieldName . '\'][\'config\']'
732 . '[\'wizards\'][\'' . $wizardName . '\'] and is changed to ' . $table
733 . '[\'columns\'][\'' . $fieldName . '\'][\'config\'] = \'colorpicker\'';
734 }
735 }
736 }
737 }
738 }
739 }
740
741 return $tca;
742 }
743
744 /**
745 * Migrates selectTree fields deprecated options
746 *
747 * @param array $tca Incoming TCA
748 * @return array Migrated TCA
749 */
750 protected function migrateSelectTreeOptions(array $tca)
751 {
752 foreach ($tca as $table => &$tableDefinition) {
753 if (!isset($tableDefinition['columns']) || !is_array($tableDefinition['columns'])) {
754 continue;
755 }
756 foreach ($tableDefinition['columns'] as $fieldName => &$fieldConfig) {
757 if (isset($fieldConfig['config']['renderType']) && $fieldConfig['config']['renderType'] === 'selectTree') {
758 if (isset($fieldConfig['config']['treeConfig']['appearance']['width'])) {
759 $this->messages[] = 'The selectTree field [\'treeConfig\'][\'appearance\'][\'width\'] setting is deprecated'
760 . ' and was removed in TCA ' . $table . '[\'columns\'][\'' . $fieldName . '\'][\'config\']'
761 . '[\'treeConfig\'][\'appearance\'][\'width\'] ';
762 unset($fieldConfig['config']['treeConfig']['appearance']['width']);
763 }
764
765 if (isset($fieldConfig['config']['treeConfig']['appearance']['allowRecursiveMode'])) {
766 $this->messages[] = 'The selectTree field [\'treeConfig\'][\'appearance\'][\'allowRecursiveMode\'] setting is deprecated'
767 . ' and was removed in TCA ' . $table . '[\'columns\'][\'' . $fieldName . '\'][\'config\']'
768 . '[\'treeConfig\'][\'appearance\'][\'allowRecursiveMode\'] ';
769 unset($fieldConfig['config']['treeConfig']['appearance']['allowRecursiveMode']);
770 }
771
772 if (isset($fieldConfig['config']['autoSizeMax'])) {
773 $this->messages[] = 'The selectTree field [\'autoSizeMax\'] setting is deprecated'
774 . ' and was removed in TCA ' . $table . '[\'columns\'][\'' . $fieldName . '\'][\'config\'][\'autoSizeMax\'].'
775 . ' The \'size\' value was adapted to the previous autoSizeMax value';
776 $fieldConfig['config']['size'] = $fieldConfig['config']['autoSizeMax'];
777 unset($fieldConfig['config']['autoSizeMax']);
778 }
779 }
780 }
781 }
782 return $tca;
783 }
784
785 /**
786 * Migrates selectTree fields deprecated options
787 *
788 * @param array $tca Incoming TCA
789 * @return array Migrated TCA
790 */
791 protected function migrateTSconfigSoftReferences(array $tca)
792 {
793 foreach ($tca as $table => &$tableDefinition) {
794 if (!isset($tableDefinition['columns']) || !is_array($tableDefinition['columns'])) {
795 continue;
796 }
797 foreach ($tableDefinition['columns'] as $fieldName => &$fieldConfig) {
798 if (isset($fieldConfig['config'])) {
799 if (isset($fieldConfig['config']['softref'])) {
800 $softReferences = array_flip(GeneralUtility::trimExplode(',', $fieldConfig['config']['softref']));
801 $changed = false;
802 if (isset($softReferences['TSconfig'])) {
803 $changed = true;
804 unset($softReferences['TSconfig']);
805 }
806 if (isset($softReferences['TStemplate'])) {
807 $changed = true;
808 unset($softReferences['TStemplate']);
809 }
810 if ($changed) {
811 if (!empty($softReferences)) {
812 $softReferences = array_flip($softReferences);
813 $fieldConfig['config']['softref'] = implode(',', $softReferences);
814 } else {
815 unset($fieldConfig['config']['softref']);
816 }
817 $this->messages[] = 'The soft reference setting using \'TSconfig\' and '
818 . '\'TStemplate\' was removed in TCA ' . $table . '[\'columns\']'
819 . '[\'' . $fieldName . '\'][\'config\'][\'softref\']';
820 }
821 }
822 }
823 }
824 }
825 return $tca;
826 }
827
828 /**
829 * Removes the option "showIfRTE" for TCA type "check"
830 *
831 * @param array $tca Incoming TCA
832 * @return array Migrated TCA
833 */
834 protected function migrateShowIfRteOption(array $tca)
835 {
836 foreach ($tca as $table => &$tableDefinition) {
837 if (!isset($tableDefinition['columns']) || !is_array($tableDefinition['columns'])) {
838 continue;
839 }
840 foreach ($tableDefinition['columns'] as $fieldName => &$fieldConfig) {
841 if (isset($fieldConfig['config']) && $fieldConfig['config']['type'] === 'check') {
842 if (isset($fieldConfig['config']['showIfRTE'])) {
843 unset($fieldConfig['config']['showIfRTE']);
844 $this->messages[] = 'The TCA setting \'showIfRTE\' was removed '
845 . 'in TCA ' . $table . '[\'columns\'][\'' . $fieldName . '\'][\'config\']';
846 }
847 }
848 }
849 }
850 return $tca;
851 }
852 }