Project

General

Profile

Actions

Bug #102911

closed

Maintenance > Manage Language Packs : list of language packs for extensions does not appear in the modal window

Added by RVVN no-lastname-given 3 months ago. Updated 3 months ago.

Status:
Resolved
Priority:
Should have
Assignee:
-
Category:
Backend JavaScript
Target version:
-
Start date:
2024-01-24
Due date:
% Done:

100%

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

Description

In Maintenance module, when opening the modal to manage language packs, the following Javascript error occurs :

LanguagePacks.js?bust=1706035863:13 Uncaught (in promise) TypeError: t.activeLanguages.forEach is not a function
    at g.extensionMatrixHtml (LanguagePacks.js?bust=1706035863:13:9297)
    at LanguagePacks.js?bust=1706035863:13:2610
extensionMatrixHtml @ LanguagePacks.js?bust=1706035863:13
(anonymous) @ LanguagePacks.js?bust=1706035863:13

It's because `t.activeLanguages` it not an array but a JSON object.
As a result, the list of language packs for extensions does not appear in the modal window.

Explanation :

The XHR call to /typo3/install.php?install[controller]=maintenance&install[context]=backend&install[action]=languagePacksGetData returns this kind of JSON data :

{
    "success": true,
    "languages": [
        [...],
        {
            "iso": "fr",
            "name": "French",
            "active": true,
            "lastUpdate": "23-01-24 18:51",
            "dependencies": []
        },
        [...]
    ],
    "extensions": [
        {
            "key": "adminpanel",
            "title": "TYPO3 Admin Panel",
            "icon": "/typo3/sysext/adminpanel/Resources/Public/Icons/Extension.png",
            "packs": [
                {
                    "iso": "fr",
                    "exists": true,
                    "lastUpdate": null
                }
            ]
        },
        [...]
    ],
    "activeLanguages": {
        "19": "fr" 
    },
    "activeExtensions": [
        "adminpanel",
        "backend",
        "belog",
        [...],
        "t3editor",
        "tstemplate" 
    ],
    "html": "..." 
}

The LanguagePackService->getActiveLanguages() function returns an array which is a trimmed version of $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['lang']['availableLanguages'] (all empty values are removed).
Thus the indexes are not a continous numeric sequence.

But according to the official documentation (https://www.php.net/manual/en/function.json-encode.php#refsect1-function.json-encode-notes) :

When encoding an array, if the keys are not a continuous numeric sequence starting from 0, all keys are encoded as strings, and specified explicitly for each key-value pair.

Examples taken from this documentation :

Sequential array
array(4) {
  [0]=>
  string(3) "foo" 
  [1]=>
  string(3) "bar" 
  [2]=>
  string(3) "baz" 
  [3]=>
  string(5) "blong" 
}
string(27) "["foo","bar","baz","blong"]" 

Non-sequential array
array(4) {
  [1]=>
  string(3) "foo" 
  [2]=>
  string(3) "bar" 
  [3]=>
  string(3) "baz" 
  [4]=>
  string(5) "blong" 
}
string(43) "{"1":"foo","2":"bar","3":"baz","4":"blong"}" 

Sequential array with one key unset
array(3) {
  [0]=>
  string(3) "foo" 
  [2]=>
  string(3) "baz" 
  [3]=>
  string(5) "blong" 
}
string(33) "{"0":"foo","2":"baz","3":"blong"}" 

Workaround / Fix :

At this point, it seems we only need ISO values, so a potential workaround/fix may be to apply array_values to the active languages in the JSON response of MaintenanceController->languagePacksGetDataAction() :

public function languagePacksGetDataAction(ServerRequestInterface $request): ResponseInterface
    {
        [...]

        return new JsonResponse([
            'success' => true,
            'languages' => $languagePackService->getLanguageDetails(),
            'extensions' => $extensions,
            'activeLanguages' => array_values($languagePackService->getActiveLanguages()), // HERE
            'activeExtensions' => array_column($extensions, 'key'),
            'html' => $view->render(),
        ]);
    }

Files

issue - extensions language packs not loaded in modal.png (54.6 KB) issue - extensions language packs not loaded in modal.png Issue : language packs for extensions are not loaded in modal RVVN no-lastname-given, 2024-01-24 09:42
after fix with array_values.png (88.6 KB) after fix with array_values.png After fix with array_values : language packs for extensions are loaded in modal RVVN no-lastname-given, 2024-01-24 09:42
Actions #1

Updated by RVVN no-lastname-given 3 months ago

  • Description updated (diff)
Actions #3

Updated by Gerrit Code Review 3 months ago

  • Status changed from New to Under Review

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

Actions #4

Updated by Gerrit Code Review 3 months ago

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

Actions #5

Updated by Gerrit Code Review 3 months ago

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

Actions #6

Updated by Oliver Bartsch 3 months ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #7

Updated by RVVN no-lastname-given 3 months ago

Any hope to see it backported to v11 ?
I know that's not a priority fix but it's a small and easy no brainer one :)

Actions

Also available in: Atom PDF