You are here

public function Language::setValue in Drupal 8

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. 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 51

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);
  }
}