W3cubDocs

/Drupal 8

public function FieldItemList::setValue

public FieldItemList::setValue($values, $notify = TRUE)

Overrides \Drupal\Core\TypedData\TypedData::setValue().

Parameters

array|null $values: An array of values of the field items, or NULL to unset the field.

Overrides ItemList::setValue

File

core/lib/Drupal/Core/Field/FieldItemList.php, line 112

Class

FieldItemList
Represents an entity field; that is, a list of field item objects.

Namespace

Drupal\Core\Field

Code

public function setValue($values, $notify = TRUE) {
  // Support passing in only the value of the first item, either as a literal
  // (value of the first property) or as an array of properties.
  if (isset($values) && (!is_array($values) || (!empty($values) && !is_numeric(current(array_keys($values)))))) {
    $values = array(0 => $values);
  }
  parent::setValue($values, $notify);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Field!FieldItemList.php/function/FieldItemList::setValue/8.1.x