contao / core

Contao 3 → see contao/contao for Contao 4
GNU Lesser General Public License v3.0
491 stars 213 forks source link

MetaWizard shows the languages in the wrong order #8855

Closed intco closed 6 years ago

intco commented 6 years ago

https://github.com/contao/core/blob/c7f0310ebd3f4e8b32a82f10f9ffa6827ab4b2a3/system/modules/core/widgets/MetaWizard.php#L110

The "array_intersect_key" call nullifies the array_flip one.

just replace the highlighted line:

$languages = array_intersect_key($languages, array_flip($objRootLangs->fetchEach('language')));

with the following:

$_languages = array();

foreach ($objRootLangs->fetchEach('language') as $_lang) {

    if (!empty($languages[$_lang]))
    {
        $_languages[$_lang] = $languages[$_lang];
    }
}

$languages = $_languages; 

The above code honors the array_flip call.

leofeyer commented 6 years ago

How do I reproduce the initial problem?

intco commented 6 years ago

Create two website root with the following languages: it and en (i.e. the first root page with language it and the second root page with language en)

Then upload a file and set meta data. The first language metaWizard shows is "english" I think it should be "italian".

fritzmg commented 6 years ago

Which back end language did you set?

intco commented 6 years ago

The backend language it's not relevant.

I think it's due to the asort call at

https://github.com/contao/core/blob/c7f0310ebd3f4e8b32a82f10f9ffa6827ab4b2a3/system/modules/core/library/Contao/System.php#L437

because of the asort call the languages will be shown in alfabetically order so "Inglese" (italian word for english) will be ever shows before "Italiano" (italian word for italian)

intco commented 6 years ago

I think this: https://github.com/contao/core/blob/c7f0310ebd3f4e8b32a82f10f9ffa6827ab4b2a3/system/modules/core/widgets/MetaWizard.php#L109

should also be:

$objRootLangs = $this->Database->query("SELECT REPLACE(language, '-', '_') AS language FROM tl_page WHERE type='root' ORDER BY sorting");

so these lines: https://github.com/contao/core/blob/c7f0310ebd3f4e8b32a82f10f9ffa6827ab4b2a3/system/modules/core/widgets/MetaWizard.php#L109-L110

should be replaced (i've changed variables names for readability) with:

$objRootLangs = $this->Database->query("SELECT REPLACE(language, '-', '_') AS language FROM tl_page WHERE type='root' ORDER BY sorting");

$siteLanguages = array();

foreach ($objRootLangs->fetchEach('language') as $rootLang) {

    if (!empty($languages[$rootLang]))
    {
        $siteLanguages[$rootLang] = $languages[$rootLang];
    }
}

$languages = $siteLanguages; 

Maybe a more correct approach will be to first shows the "fallback language" root and then show others in the order they appear in the "site structure"

leofeyer commented 6 years ago

The backend language it's not relevant.

It is relevant, so which language did you use?

intco commented 6 years ago

The backend language is set to "Italian"

leofeyer commented 6 years ago

The languages being ordered alphabetically is correct. However, we have recently made a change in contao/core-bundle@94181f7ca21361576c5511f461d18957cf5c28cf so that languages matching the back end user's language are shown first. Maybe we should backport this?