You are here

public static function ConfigurableLanguage::createFromLangcode in Drupal 10

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

159 calls to ConfigurableLanguage::createFromLangcode()
AdminPathEntityConverterLanguageTest::setUp in core/modules/language/tests/src/Functional/AdminPathEntityConverterLanguageTest.php
BasicAuthTest::testLocale in core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php
Tests compatibility with locale/UI translation.
BlockContentFieldFilterTest::setUp in core/modules/block_content/tests/src/Functional/Views/BlockContentFieldFilterTest.php
BlockUiTest::testBlockPlacementIndicator in core/modules/block/tests/src/Functional/BlockUiTest.php
Tests the block placement indicator.
BulkFormTest::setUp in core/modules/node/tests/src/Functional/Views/BulkFormTest.php

... 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' => $standard_languages[$langcode][2] ?? static::DIRECTION_LTR,
    ]);
  }
}