function LanguageManager::filterLanguages
Same name in other branches
- 9 core/lib/Drupal/Core/Language/LanguageManager.php \Drupal\Core\Language\LanguageManager::filterLanguages()
- 8.9.x core/lib/Drupal/Core/Language/LanguageManager.php \Drupal\Core\Language\LanguageManager::filterLanguages()
- 11.x core/lib/Drupal/Core/Language/LanguageManager.php \Drupal\Core\Language\LanguageManager::filterLanguages()
Filters the full list of languages based on the value of the flag.
The locked languages are removed by default.
Parameters
\Drupal\Core\Language\LanguageInterface[] $languages: Array with languages to be filtered.
int $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 value
\Drupal\Core\Language\LanguageInterface[] An associative array of languages, keyed by the language code.
2 calls to LanguageManager::filterLanguages()
- ConfigurableLanguageManager::getLanguages in core/
modules/ language/ src/ ConfigurableLanguageManager.php - LanguageManager::getLanguages in core/
lib/ Drupal/ Core/ Language/ LanguageManager.php
File
-
core/
lib/ Drupal/ Core/ Language/ LanguageManager.php, line 413
Class
- LanguageManager
- Class responsible for providing language support on language-unaware sites.
Namespace
Drupal\Core\LanguageCode
protected function filterLanguages(array $languages, $flags = LanguageInterface::STATE_CONFIGURABLE) {
// STATE_ALL means we don't actually filter, so skip the rest of the method.
if ($flags == LanguageInterface::STATE_ALL) {
return $languages;
}
$filtered_languages = [];
// Add the site's default language if requested.
if ($flags & LanguageInterface::STATE_SITE_DEFAULT) {
// Setup a language to have the defaults with data appropriate of the
// default language only for runtime.
$defaultLanguage = $this->getDefaultLanguage();
$default = new Language([
'id' => $defaultLanguage->getId(),
'name' => new TranslatableMarkup("Site's default language (@lang_name)", [
'@lang_name' => $defaultLanguage->getName(),
]),
'direction' => $defaultLanguage->getDirection(),
'weight' => $defaultLanguage->getWeight(),
]);
$filtered_languages[LanguageInterface::LANGCODE_SITE_DEFAULT] = $default;
}
foreach ($languages as $id => $language) {
if ($language->isLocked() && $flags & LanguageInterface::STATE_LOCKED || !$language->isLocked() && $flags & LanguageInterface::STATE_CONFIGURABLE) {
$filtered_languages[$id] = $language;
}
}
return $filtered_languages;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.