sabbelasichon / typo3-rector

Rector for TYPO3
MIT License
224 stars 62 forks source link

[BUG]: SimplifyCheckboxItemsTCARector removes non-empty labels (TYPO3 11) #4298

Closed LeoniePhiline closed 2 weeks ago

LeoniePhiline commented 1 month ago

Minimal PHP Code Causing Issue

<?php

return [
  'columns' => [
     'col_name' => [
         'config'   => [
             'type'       => 'check',
             'renderType' => 'checkboxToggle',
             'items'      => [
                 ['LLL:EXT:some_extension/Resources/Private/Language/locallang_db.xlf:some_label', ''],
             ],
         ],
     ],
  ],
];

Applied rules

SimplifyCheckboxItemsTCARector

Expected Behaviour

<?php

return [
  'columns' => [
     'col_name' => [
         'config'   => [
             'type'       => 'check',
             'renderType' => 'checkboxToggle',
             'items'      => [
                 [0 => 'LLL:EXT:some_extension/Resources/Private/Language/locallang_db.xlf:some_label'],
             ],
         ],
     ],
  ],
];

Note: Manually changing ['LLL:EXT:some_extension/Resources/Private/Language/locallang_db.xlf:some_label', ''] to [0 => 'LLL:EXT:some_extension/Resources/Private/Language/locallang_db.xlf:some_label'] prevents SimplifyCheckboxItemsTCARector from triggering and falsely removing the label.

Package Version

2.6.4

PHP Version

8.3.10

TYPO3 Version

11.5.38

Notes

Actual behavior:

<?php

return [
  'columns' => [
     'col_name' => [
         'config'   => [
             'type'       => 'check',
             'renderType' => 'checkboxToggle',
         ],
     ],
  ],
];

The ['items'][...][0] label gets lost even if it is non-empty. Docs: https://docs.typo3.org/m/typo3/reference-tca/11.5/en-us/ColumnsConfig/Type/Check/Toggle.html#tca_example_checkbox_17

Later, for TYPO3 12, the 0 => will be translated into 'label' =>. Docs: https://docs.typo3.org/m/typo3/reference-tca/12.4/en-us/ColumnsConfig/Type/Check/Toggle.html#columns-check-checkboxToggle-examples-17

helsner commented 3 weeks ago

@simonschaufi // @sabbelasichon Here it is kinda the question what we want to do. Basically the original config is wrong, that's why the items config gets killed. Should we still check for this and prevent a removal?

LeoniePhiline commented 3 weeks ago

In which way is the original config wrong?

To me, it appears to match the TYPO3 10 example at https://docs.typo3.org/m/typo3/reference-tca/10.4/en-us/ColumnsConfig/Type/checkDefault.html#examples

I do see that the checkbox toggle examples show empty labels https://docs.typo3.org/m/typo3/reference-tca/10.4/en-us/ColumnsConfig/Type/checkboxToggle.html#examples

However, the label is displayed, and checkbox toggles with non empty label and empt value can also be found in TYPO3 10 core.

Non-empty labels, and labels with implicit numeric keys, are also shown in https://docs.typo3.org/m/typo3/reference-tca/10.4/en-us/ColumnsConfig/Type/checkboxToggle.html#items