MetaWizard shows the languages in the wrong order
Closed this issue · 8 comments
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.
How do I reproduce the initial problem?
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".
Which back end language did you set?
The backend language it's not relevant.
I think it's due to the asort call at
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)
I think this:
should also be:
$objRootLangs = $this->Database->query("SELECT REPLACE(language, '-', '_') AS language FROM tl_page WHERE type='root' ORDER BY sorting");
so these lines:
core/system/modules/core/widgets/MetaWizard.php
Lines 109 to 110 in c7f0310
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"
The backend language it's not relevant.
It is relevant, so which language did you use?
The backend language is set to "Italian"
The languages being ordered alphabetically is correct. However, we have recently made a change in contao/core-bundle@94181f7 so that languages matching the back end user's language are shown first. Maybe we should backport this?