function FieldItemBase::setValue

Same name in other branches
  1. 9 core/lib/Drupal/Core/Field/FieldItemBase.php \Drupal\Core\Field\FieldItemBase::setValue()
  2. 8.9.x core/lib/Drupal/Core/Field/FieldItemBase.php \Drupal\Core\Field\FieldItemBase::setValue()
  3. 11.x core/lib/Drupal/Core/Field/FieldItemBase.php \Drupal\Core\Field\FieldItemBase::setValue()

Overrides Map::setValue

7 calls to FieldItemBase::setValue()
CreatedItem::applyDefaultValue in core/lib/Drupal/Core/Field/Plugin/Field/FieldType/CreatedItem.php
FieldTestItem::postSave in core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/FieldTestItem.php
FieldTestItem::preSave in core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/FieldTestItem.php
LanguageItem::setValue in core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php
LinkItem::setValue in core/modules/link/src/Plugin/Field/FieldType/LinkItem.php

... See full list

3 methods override FieldItemBase::setValue()
LanguageItem::setValue in core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php
LinkItem::setValue in core/modules/link/src/Plugin/Field/FieldType/LinkItem.php
MapItem::setValue in core/lib/Drupal/Core/Field/Plugin/Field/FieldType/MapItem.php

File

core/lib/Drupal/Core/Field/FieldItemBase.php, line 118

Class

FieldItemBase
An entity field item.

Namespace

Drupal\Core\Field

Code

public function setValue($values, $notify = TRUE) {
    // Treat the values as property value of the first property, if no array is
    // given.
    if (isset($values) && !is_array($values)) {
        $keys = array_keys($this->definition
            ->getPropertyDefinitions());
        $values = [
            $keys[0] => $values,
        ];
    }
    parent::setValue($values, $notify);
}

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