function ConfigurableLanguageManager::getLanguages
Same name in other branches
- 9 core/modules/language/src/ConfigurableLanguageManager.php \Drupal\language\ConfigurableLanguageManager::getLanguages()
- 8.9.x core/modules/language/src/ConfigurableLanguageManager.php \Drupal\language\ConfigurableLanguageManager::getLanguages()
- 10 core/modules/language/src/ConfigurableLanguageManager.php \Drupal\language\ConfigurableLanguageManager::getLanguages()
Overrides LanguageManager::getLanguages
5 calls to ConfigurableLanguageManager::getLanguages()
- ConfigurableLanguageManager::getFallbackCandidates in core/
modules/ language/ src/ ConfigurableLanguageManager.php - Returns the language fallback candidates for a given context.
- ConfigurableLanguageManager::getNativeLanguages in core/
modules/ language/ src/ ConfigurableLanguageManager.php - Returns a list of languages set up on the site in their native form.
- ConfigurableLanguageManager::getStandardLanguageListWithoutConfigured in core/
modules/ language/ src/ ConfigurableLanguageManager.php - Returns the standard language list excluding already configured languages.
- ConfigurableLanguageManager::isMultilingual in core/
modules/ language/ src/ ConfigurableLanguageManager.php - Returns whether or not the site has more than one language added.
- ConfigurableLanguageManager::updateLockedLanguageWeights in core/
modules/ language/ src/ ConfigurableLanguageManager.php - Updates locked system language weights.
File
-
core/
modules/ language/ src/ ConfigurableLanguageManager.php, line 279
Class
- ConfigurableLanguageManager
- Overrides default LanguageManager to provide configured languages.
Namespace
Drupal\languageCode
public function getLanguages($flags = LanguageInterface::STATE_CONFIGURABLE) {
// If a config override is set, cache using that language's ID.
if ($override_language = $this->getConfigOverrideLanguage()) {
$static_cache_id = $override_language->getId();
}
else {
$static_cache_id = $this->getCurrentLanguage()
->getId();
}
if (!isset($this->languages[$static_cache_id][$flags])) {
// Initialize the language list with the default language and default
// locked languages. These cannot be removed. This serves as a fallback
// list if this method is invoked while the language module is installed
// and the configuration entities for languages are not yet fully
// imported.
$default = $this->getDefaultLanguage();
$languages = [
$default->getId() => $default,
];
$languages += $this->getDefaultLockedLanguages($default->getWeight());
// Load configurable languages on top of the defaults. Ideally this could
// use the entity API to load and instantiate ConfigurableLanguage
// objects. However the entity API depends on the language system, so that
// would result in infinite loops. We use the configuration system
// directly and instantiate runtime Language objects. When language
// entities are imported those cover the default and locked languages, so
// site-specific configuration will prevail over the fallback values.
// Having them in the array already ensures if this is invoked in the
// middle of importing language configuration entities, the defaults are
// always present.
$config_ids = $this->configFactory
->listAll('language.entity.');
foreach ($this->configFactory
->loadMultiple($config_ids) as $config) {
$data = $config->get();
$data['name'] = $data['label'];
$languages[$data['id']] = new Language($data);
}
Language::sort($languages);
// Filter the full list of languages based on the value of $flags.
$this->languages[$static_cache_id][$flags] = $this->filterLanguages($languages, $flags);
}
return $this->languages[$static_cache_id][$flags];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.