You are here

public function LinkItem::setValue in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/link/src/Plugin/Field/FieldType/LinkItem.php \Drupal\link\Plugin\Field\FieldType\LinkItem::setValue()

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

Parameters

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

Overrides FieldItemBase::setValue

File

core/modules/link/src/Plugin/Field/FieldType/LinkItem.php, line 180

Class

LinkItem
Plugin implementation of the 'link' field type.

Namespace

Drupal\link\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 += [
      'options' => [],
    ];

    // Unserialize the values, this is deprecated as the storage takes care of
    // this, options must not be passed as a string anymore.
    if (is_string($values['options'])) {
      @trigger_error('Support for passing options as a serialized string is deprecated in 8.7.0 and will be removed before Drupal 9.0.0. Pass them as an array instead. See https://www.drupal.org/node/2961643.', E_USER_DEPRECATED);
      $values['options'] = unserialize($values['options'], [
        'allowed_classes' => FALSE,
      ]);
    }
  }
  parent::setValue($values, $notify);
}