You are here

public function BlockFieldItem::setValue in Block field 8

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

Parameters

array|null $values: An array of property values.

Overrides FieldItemBase::setValue

File

src/Plugin/Field/FieldType/BlockFieldItem.php, line 145

Class

BlockFieldItem
Plugin implementation of the 'block_field' field type.

Namespace

Drupal\block_field\Plugin\Field\FieldType

Code

public function setValue($values, $notify = TRUE) {

  // Treat the values as property value of the main property, if no array is
  // given.
  if (isset($values) && !is_array($values)) {
    $values = [
      static::mainPropertyName() => $values,
    ];
  }
  if (isset($values)) {
    $values += [
      'settings' => [],
    ];
  }

  // Unserialize the values.
  if (is_string($values['settings'])) {
    $values['settings'] = unserialize($values['settings']);
  }
  parent::setValue($values, $notify);
}