function LinkItem::setValue

Same name in other branches
  1. 9 core/modules/link/src/Plugin/Field/FieldType/LinkItem.php \Drupal\link\Plugin\Field\FieldType\LinkItem::setValue()
  2. 10 core/modules/link/src/Plugin/Field/FieldType/LinkItem.php \Drupal\link\Plugin\Field\FieldType\LinkItem::setValue()
  3. 11.x core/modules/link/src/Plugin/Field/FieldType/LinkItem.php \Drupal\link\Plugin\Field\FieldType\LinkItem::setValue()

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);
}

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