function Language::__construct

Same name in this branch
  1. 11.x core/modules/language/src/Plugin/Condition/Language.php \Drupal\language\Plugin\Condition\Language::__construct()
  2. 11.x core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Language.php \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Language::__construct()
Same name and namespace in other branches
  1. 9 core/modules/language/src/Plugin/Condition/Language.php \Drupal\language\Plugin\Condition\Language::__construct()
  2. 9 core/lib/Drupal/Core/Language/Language.php \Drupal\Core\Language\Language::__construct()
  3. 8.9.x core/modules/language/src/Plugin/Condition/Language.php \Drupal\language\Plugin\Condition\Language::__construct()
  4. 8.9.x core/lib/Drupal/Core/Language/Language.php \Drupal\Core\Language\Language::__construct()
  5. 10 core/modules/language/src/Plugin/Condition/Language.php \Drupal\language\Plugin\Condition\Language::__construct()
  6. 10 core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Language.php \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Language::__construct()
  7. 10 core/lib/Drupal/Core/Language/Language.php \Drupal\Core\Language\Language::__construct()

Constructs a new class instance.

Parameters

array $values: An array of property values, keyed by property name, used to construct the language.

File

core/lib/Drupal/Core/Language/Language.php, line 77

Class

Language
An object containing the information for an interface language.

Namespace

Drupal\Core\Language

Code

public function __construct(array $values = []) {
    // Set all the provided properties for the language.
    foreach ($values as $key => $value) {
        if (property_exists($this, $key)) {
            $this->{$key} = $value;
        }
    }
    // If some values were not set, set sane defaults of a predefined language.
    if (!isset($values['name']) || !isset($values['direction'])) {
        $predefined = LanguageManager::getStandardLanguageList();
        if (isset($predefined[$this->id])) {
            if (!isset($values['name'])) {
                $this->name = $predefined[$this->id][0];
            }
            if (!isset($values['direction']) && isset($predefined[$this->id][2])) {
                $this->direction = $predefined[$this->id][2];
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.