function ConfigurableLanguage::createFromLangcode
Same name in other branches
- 9 core/modules/language/src/Entity/ConfigurableLanguage.php \Drupal\language\Entity\ConfigurableLanguage::createFromLangcode()
- 8.9.x core/modules/language/src/Entity/ConfigurableLanguage.php \Drupal\language\Entity\ConfigurableLanguage::createFromLangcode()
- 11.x core/modules/language/src/Entity/ConfigurableLanguage.php \Drupal\language\Entity\ConfigurableLanguage::createFromLangcode()
Creates a configurable language object from a langcode.
Parameters
string $langcode: The language code to use to create the object.
Return value
$this
See also
\Drupal\Core\Language\LanguageManager::getStandardLanguageList()
19 calls to ConfigurableLanguage::createFromLangcode()
- ConfigurableLanguageValidationTest::setUp in core/
modules/ language/ tests/ src/ Kernel/ ConfigurableLanguageValidationTest.php - ContextualDynamicContextTest::testDifferentPermissions in core/
modules/ contextual/ tests/ src/ Functional/ ContextualDynamicContextTest.php - Tests contextual links with different permissions.
- EntityViewBuilderTest::testViewField in core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityViewBuilderTest.php - Tests EntityViewBuilder::viewField() language awareness.
- ImportForm::submitForm in core/
modules/ locale/ src/ Form/ ImportForm.php - install_download_additional_translations_operations in core/
includes/ install.core.inc - Prepares the system for import and downloads additional translations.
File
-
core/
modules/ language/ src/ Entity/ ConfigurableLanguage.php, line 272
Class
- ConfigurableLanguage
- Defines the ConfigurableLanguage entity.
Namespace
Drupal\language\EntityCode
public static function createFromLangcode($langcode) {
$standard_languages = LanguageManager::getStandardLanguageList();
if (!isset($standard_languages[$langcode])) {
// Drupal does not know about this language, so we set its values with the
// best guess. The user will be able to edit afterwards.
return static::create([
'id' => $langcode,
'label' => $langcode,
]);
}
else {
// A known predefined language, details will be filled in properly.
return static::create([
'id' => $langcode,
'label' => $standard_languages[$langcode][0],
'direction' => $standard_languages[$langcode][2] ?? static::DIRECTION_LTR,
]);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.