Bug #86985

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

Added by NGUYEN Duc Quan about 3 years ago. Updated 2 months ago.

Status:
Under Review
Priority:
Should have
Assignee:
-
Category:
Backend User Interface
Target version:
-
Start date:
2018-11-23
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
8
PHP Version:
7.0
Tags:
Complexity:
Is Regression:
Sprint Focus:

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.


Files

Screen Shot 2018-11-23 at 11.50.23.png (72 KB) Screen Shot 2018-11-23 at 11.50.23.png NGUYEN Duc Quan, 2018-11-23 14:10
Screenshot 2018-11-27 at 12.05.01.png (37.1 KB) Screenshot 2018-11-27 at 12.05.01.png Result of a translated page Filipe DA COSTA COSTA, 2018-11-27 12:05

Related issues

Related to TYPO3 Core - Bug #54131: getLabelsFromItemsList doens't return any values when no item foundClosed2013-12-02

Actions
#1

Updated by Filipe DA COSTA COSTA about 3 years ago

  • Related to Bug #54131: getLabelsFromItemsList doens't return any values when no item found added
#2

Updated by Filipe DA COSTA COSTA about 3 years ago

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.

#3

Updated by Gerrit Code Review about 3 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59156

#4

Updated by Gerrit Code Review about 3 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59156

#5

Updated by Gerrit Code Review about 3 years ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59156

#6

Updated by Gerrit Code Review almost 3 years ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59156

#7

Updated by Gerrit Code Review almost 3 years ago

Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59156

#8

Updated by Gerrit Code Review almost 3 years ago

Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59156

#9

Updated by Gerrit Code Review almost 3 years ago

Patch set 7 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59156

#10

Updated by Gerrit Code Review almost 3 years ago

Patch set 8 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/59156

#11

Updated by Gerrit Code Review almost 2 years ago

Patch set 9 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/59156

#12

Updated by Gerrit Code Review over 1 year ago

Patch set 10 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/59156

#13

Updated by Gerrit Code Review 3 months ago

Patch set 11 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/59156

#14

Updated by Gerrit Code Review 2 months ago

Patch set 12 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/59156

Also available in: Atom PDF