function ConfigurableLanguage::createFromLangcode

Same name in other branches
  1. 9 core/modules/language/src/Entity/ConfigurableLanguage.php \Drupal\language\Entity\ConfigurableLanguage::createFromLangcode()
  2. 10 core/modules/language/src/Entity/ConfigurableLanguage.php \Drupal\language\Entity\ConfigurableLanguage::createFromLangcode()
  3. 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()

14 calls to ConfigurableLanguage::createFromLangcode()
ContextualDynamicContextTest::testDifferentPermissions in core/modules/contextual/tests/src/Functional/ContextualDynamicContextTest.php
Tests contextual links with different permissions.
ImportForm::submitForm in core/modules/locale/src/Form/ImportForm.php
Form submission handler.
install_download_additional_translations_operations in core/includes/install.core.inc
Prepares the system for import and downloads additional translations.
JsonApiFunctionalMultilingualTest::setUp in core/modules/jsonapi/tests/src/Functional/JsonApiFunctionalMultilingualTest.php
LanguageConfigurationTest::testLanguageConfiguration in core/modules/language/tests/src/Functional/LanguageConfigurationTest.php
Functional tests for adding, editing and deleting languages.

... See full list

File

core/modules/language/src/Entity/ConfigurableLanguage.php, line 272

Class

ConfigurableLanguage
Defines the ConfigurableLanguage entity.

Namespace

Drupal\language\Entity

Code

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' => isset($standard_languages[$langcode][2]) ? $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.