function Language::setValue

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/TypedData/Plugin/DataType/Language.php \Drupal\Core\TypedData\Plugin\DataType\Language::setValue()
  2. 8.9.x core/lib/Drupal/Core/TypedData/Plugin/DataType/Language.php \Drupal\Core\TypedData\Plugin\DataType\Language::setValue()
  3. 10 core/lib/Drupal/Core/TypedData/Plugin/DataType/Language.php \Drupal\Core\TypedData\Plugin\DataType\Language::setValue()

Overrides TypedData::setValue().

Both the langcode and the language object may be passed as value.

Overrides TypedData::setValue

File

core/lib/Drupal/Core/TypedData/Plugin/DataType/Language.php, line 53

Class

Language
Defines the 'language' data type.

Namespace

Drupal\Core\TypedData\Plugin\DataType

Code

public function setValue($value, $notify = TRUE) {
  // Support passing language objects.
  if (is_object($value)) {
    $this->id = $value->getId();
    $this->language = $value;
  }
  elseif (isset($value) && !is_scalar($value)) {
    throw new \InvalidArgumentException('Value is no valid langcode or language object.');
  }
  else {
    $this->id = $value;
    $this->language = NULL;
  }
  // Notify the parent of any changes.
  if ($notify && isset($this->parent)) {
    $this->parent
      ->onChange($this->name);
  }
}

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