You are here

public function PluginCollectionItemBase::setValue in Plugin 8.2

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

Parameters

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

Overrides FieldItemBase::setValue

File

src/Plugin/Field/FieldType/PluginCollectionItemBase.php, line 189

Class

PluginCollectionItemBase
Provides a base for plugin collection field items.

Namespace

Drupal\plugin\Plugin\Field\FieldType

Code

public function setValue($values, $notify = TRUE) {
  if ($values instanceof PluginInspectionInterface) {
    $this
      ->setContainedPluginInstance($values);
  }
  elseif (is_array($values)) {
    if (isset($values['plugin_instance'])) {
      $this
        ->setContainedPluginInstance($values['plugin_instance']);
    }
    else {
      if (isset($values['plugin_id'])) {
        $this
          ->setContainedPluginId($values['plugin_id']);
      }
      if (isset($values['plugin_configuration'])) {
        $this
          ->setContainedPluginConfiguration($values['plugin_configuration']);
      }
    }
  }
  elseif (!is_null($values)) {
    $type = is_object($values) ? get_class($values) : gettype($values);
    throw new \InvalidArgumentException(sprintf('The value must implement %s or be an associative array, but %s was given', PluginInspectionInterface::class, $type));
  }
}