getTarget(); return isset($language) ? $language->id() : NULL; } /** * Returns all valid values for a `langcode` config value. * * @return string[] * All possible valid langcodes. This includes all langcodes in the standard * list of human languages, along with special langcodes like `und`, `zxx`, * and `site_default`, which Drupal uses internally. If any custom languages * are defined, they will be included as well. * * @see \Drupal\Core\Language\LanguageManagerInterface::getLanguages() * @see \Drupal\Core\Language\LanguageManagerInterface::getStandardLanguageList() */ public static function getAllValidLangcodes(): array { $language_manager = \Drupal::languageManager(); return array_unique([ ...array_keys($language_manager::getStandardLanguageList()), // We can't use LanguageInterface::STATE_ALL because it will exclude the // site default language in certain situations. // @see \Drupal\Core\Language\LanguageManager::filterLanguages() ...array_keys($language_manager->getLanguages(LanguageInterface::STATE_LOCKED | LanguageInterface::STATE_CONFIGURABLE | LanguageInterface::STATE_SITE_DEFAULT)), // Include special language codes used internally. LanguageInterface::LANGCODE_NOT_APPLICABLE, LanguageInterface::LANGCODE_SITE_DEFAULT, LanguageInterface::LANGCODE_DEFAULT, LanguageInterface::LANGCODE_SYSTEM, LanguageInterface::LANGCODE_NOT_SPECIFIED, ]); } }