You are here

public function ViewsReferenceItem::setValue in Views Reference Field 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldType/ViewsReferenceItem.php \Drupal\viewsreference\Plugin\Field\FieldType\ViewsReferenceItem::setValue()

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

Parameters

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

Overrides EntityReferenceItem::setValue

File

src/Plugin/Field/FieldType/ViewsReferenceItem.php, line 120

Class

ViewsReferenceItem
Defines the 'viewsreference' entity field type.

Namespace

Drupal\viewsreference\Plugin\Field\FieldType

Code

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

  // Select widget has extra layer of items.
  if (isset($values['target_id']) && is_array($values['target_id'])) {
    $values['target_id'] = isset($values['target_id'][0]['target_id']) ? $values['target_id'][0]['target_id'] : NULL;
  }

  // Empty string argument only possible if no argument supplied.
  if (isset($values['argument']) && $values['argument'] === '') {
    $values['argument'] = NULL;
  }
  parent::setValue($values, FALSE);
}