public static function CustomLanguageManager::createFromLangcode in Custom Language field 8
Creates a configurable language object from a langcode.
Copy from $language = \Drupal::languageManager()->getLanguage($langcode); Do NOT use languageManager, since it only uses installed, not custom languages.
Parameters
string $langcode: The language code to use to create the object.
Return value
\Drupal\Core\Entity\EntityInterface|\Drupal\language\Entity\ConfigurableLanguage|\Drupal\languagefield\Entity\CustomLanguage Custom language.
See also
\Drupal\Core\Language\LanguageManager::getStandardLanguageList()
1 call to CustomLanguageManager::createFromLangcode()
- LanguageFormatter::viewValue in src/
Plugin/ Field/ FieldFormatter/ LanguageFormatter.php - Generate the output appropriate for one field item.
File
- src/
Entity/ CustomLanguageManager.php, line 71
Class
- CustomLanguageManager
- Defines the CustomLanguage entity.
Namespace
Drupal\languagefield\EntityCode
public static function createFromLangcode($langcode) {
$custom_languages = CustomLanguageManager::getCustomLanguageList();
if (isset($custom_languages[$langcode])) {
// A known predefined language, details will be filled in properly.
$custom_language = CustomLanguage::create([
'id' => $langcode,
'label' => $custom_languages[$langcode][0],
'direction' => isset($custom_languages[$langcode][2]) ? $custom_languages[$langcode][2] : ConfigurableLanguage::DIRECTION_LTR,
]);
return $custom_language;
}
// $langcode refers to a standard language.
return ConfigurableLanguage::createFromLangcode($langcode);
}