protected LanguageManager::filterLanguages(array $languages, $flags = LanguageInterface::STATE_CONFIGURABLE)
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.
File
- core/lib/Drupal/Core/Language/LanguageManager.php, line 388
Class
- LanguageManager
- Class responsible for providing language support on language-unaware sites.
Namespace
Drupal\Core\Language
Code
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 = array(); // 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( array( 'id' => $defaultLanguage->getId(), 'name' => new TranslatableMarkup("Site's default language (@lang_name)", array('@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; }
Please login to continue.