Commit 7f708faf authored by alexpott's avatar alexpott

Issue #2860277 by ritzz, gaurav.kapoor, vaplas: update_language_list() should be removed

parent 61b0a38e
......@@ -687,78 +687,3 @@ function update_replace_permissions($replace) {
->save();
}
}
/**
* Returns a list of languages set up on the site during upgrades.
*
* @param $flags
* (optional) Specifies the state of the languages that have to be returned.
* It can be: LanguageInterface::STATE_CONFIGURABLE,
* LanguageInterface::STATE_LOCKED, or LanguageInterface::STATE_ALL.
*
* @return \Drupal\Core\Language\LanguageInterface[]
* An associative array of languages, keyed by the language code, ordered by
* weight ascending and name ascending.
*/
function update_language_list($flags = LanguageInterface::STATE_CONFIGURABLE) {
$languages = &drupal_static(__FUNCTION__);
// Initialize master language list.
if (!isset($languages)) {
// Initialize local language list cache.
$languages = [];
// Fill in master language list based on current configuration.
$default = \Drupal::languageManager()->getDefaultLanguage();
if (\Drupal::languageManager()->isMultilingual() || \Drupal::moduleHandler()->moduleExists('language')) {
// Use language module configuration if available. We can not use
// entity_load_multiple() because this breaks during updates.
$language_entities = \Drupal::configFactory()->listAll('language.entity.');
// Initialize default property so callers have an easy reference and can
// save the same object without data loss.
foreach ($language_entities as $langcode_config_name) {
$langcode = substr($langcode_config_name, strlen('language.entity.'));
$info = \Drupal::config($langcode_config_name)->get();
$languages[$langcode] = new Language([
'default' => ($info['id'] == $default->getId()),
'name' => $info['label'],
'id' => $info['id'],
'direction' => $info['direction'],
'locked' => $info['locked'],
'weight' => $info['weight'],
]);
}
Language::sort($languages);
}
else {
// No language module, so use the default language only.
$languages = [$default->getId() => $default];
// Add the special languages, they will be filtered later if needed.
$languages += \Drupal::languageManager()->getDefaultLockedLanguages($default->getWeight());
}
}
// Filter the full list of languages based on the value of the $all flag. By
// default we remove the locked languages, but the caller may request for
// those languages to be added as well.
$filtered_languages = [];
// Add the site's default language if flagged as allowed value.
if ($flags & LanguageInterface::STATE_SITE_DEFAULT) {
$default = \Drupal::languageManager()->getDefaultLanguage();
// Rename the default language.
$default->setName(t("Site's default language (@lang_name)", ['@lang_name' => $default->getName()]));
$filtered_languages[LanguageInterface::LANGCODE_SITE_DEFAULT] = $default;
}
foreach ($languages as $langcode => $language) {
if (($language->isLocked() && !($flags & LanguageInterface::STATE_LOCKED)) || (!$language->isLocked() && !($flags & LanguageInterface::STATE_CONFIGURABLE))) {
continue;
}
$filtered_languages[$langcode] = $language;
}
return $filtered_languages;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment