Issue Bug Closed

#86985itemsProcFunc for select->selectSingle shows key instead of label in page translation

NGUYEN Duc Quan 11/23/18, 14:20 updated 04/16/25, 09:35

Description

Hi,

I noticed that when using ‘itemsProcFunc’ I get a strange behaviour when translating a page. When translating the page in the BE then the key is shown instead of the label. This behaviour doesn’t appear to be when using ‘items’ to render a select list. Shouldn’t the label be shown instead of the key like it is for rendering lists with ‘items’? Or am I missing an implementation step?

...

// Here's the snippet from the tca where I override pages
    'tx_abcde_blog_media_type' => [
        'exclude' => 0,
        'label' => 'Blog type',
        'config' => [
            'type' => 'select',
            'renderType' => 'selectSingle',
            'itemsProcFunc' => "XYZ\\Abcde\\Lists\\MediaTypes->tcaMediaTypes",
        ],
        'displayCond' => 'FIELD:tx_abcde_blog_content_type:!=:category',
    ]

...

// Here are the functions I am using

    static public function tcaMediaTypes($config){
        $config['items'] = \XYZ\\Abcde\Helper\TCA::arrayToList(self::mediaTypes());
        return $config;
    }

    static function mediaTypes()
    {

        return [
            0 => Languages::translate('blog.mediatypes.0'),
            1 => Languages::translate('blog.mediatypes.1'),
            2 => Languages::translate('blog.mediatypes.2'),
            3 => Languages::translate('blog.mediatypes.3')
        ];

    }

    public static function arrayToList($aArray)
    {

        $list = [];

        foreach ($aArray as $key => $value) {
            $list[] = [$value, $key];
        }

        return $list;

    }

...

I attached a screenshot !Screen Shot 2018-11-23 at 11.50.23.png! to show the issue.

Reviews 1

Files 2

History 517

  1. Filipe DA COSTA commented and changed attached Screenshot 2018-11-27 at 12.05.01.png <span data-processor="relativetime" data-value="2018-11-27T12:08:36+00:00" > 11/27/18, 12:08 </span>

    I made some tests with a fresh Typo3 8.7.20 instance and can confirm the above issue.

    TCA for `pages`:

    
    $tca = [
    
        'tx_apxsample_category' => [
            'exclude' => 1,
            'label'   => 'Category',
            'config'  => [
                'type'          => 'select',
                'renderType'     => 'selectSingle',
                'size'          => '1',
                'itemsProcFunc' => "Vendor\\Apxsample\\Lists\\Categories->tcaCategories",
            ]
        ],
    
        'tx_apxsample_category2' => [
            'exclude' => 1,
            'label'   => 'Category',
            'config'  => [
                'type'          => 'select',
                'renderType'     => 'selectSingle',
                'size'          => '1',
                'items' => [
                    ['Category A', 0 ],
                    ['Category B', 1 ],
                    ['Category C', 2 ],
                    ['Category D', 3 ]
                ],
            ]
        ],
    
    ];

    TCA for `pages_language_overlay`:

    $tca = [
    
        'tx_apxsample_category' => [
            'exclude' => 1,
            'label'   => 'Category',
            'config'  => [
                'type'          => 'select',
                'renderType'     => 'selectSingle',
                'size'          => '1',
                'itemsProcFunc' => "Vendor\\Apxsample\\Lists\\Categories->tcaCategories",
                'behaviour' => [
                        'allowLanguageSynchronization' => 1
                ]
            ]
        ],
    
        'tx_apxsample_category2' => [
            'exclude' => 1,
            'label'   => 'Category',
            'config'  => [
                'type'          => 'select',
                'renderType'     => 'selectSingle',
                'size'          => '1',
                'items' => [
                    ['Category A', 0 ],
                    ['Category B', 1 ],
                    ['Category C', 2 ],
                    ['Category D', 3 ]
                ],
                'behaviour' => [
                    'allowLanguageSynchronization' => 1
                ]
            ]
        ],
    
    ];

    Here’s the list used by itemsProcFunc:

        static public function tcaCategories($config){
    
            $config['items'] = [
                ['Category A', 0 ],
                ['Category B', 1 ],
                ['Category C', 2 ],
                ['Category D', 3 ]
            ];
    
            return $config;
        }

    Result of a translated page (see attached image)

    `BackendUtility::getLabelsFromItemsList` does not support `itemsProcFunc` and it produces a display bug on `otherLanguageContent` field when working with a `select`.

    The code that should return the label, only checks for `items` and does not try to process that `itemsProcFunc`: https://github.com/TYPO3/TYPO3.CMS/blob/master/typo3/sysext/backend/Classes/Utility/BackendUtility.php#L1732

    `BackendUtility::getLabelsFromItemsList` should also check if `itemsProcFunc` is in the config and call `GeneralUtility::callUserFunction` in that case. (I understand that some changes to callUserFunction could be needed, specially for the $ref part)

    In the PHPDoc, there’s `NOTE: this does not take itemsProcFunc into account`, but there’s nothing about that in the documentation.

  2. Gerrit Code Review pushed patch set 1 for master to change 59156 status New Under Review <span data-processor="relativetime" data-value="2018-12-14T14:53:13+00:00" > 12/14/18, 14:53 </span>