You are here

public function ColorItem::setValue in Color API 8

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

Parameters

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

Overrides FieldItemBase::setValue

File

src/Plugin/Field/FieldType/ColorItem.php, line 84

Class

ColorItem
Provides the Color field.

Namespace

Drupal\colorapi\Plugin\Field\FieldType

Code

public function setValue($values, $notify = TRUE) {
  $values['name'] = isset($values['name']) ? $values['name'] : '';
  $this
    ->setName($values['name'], $notify);
  $color_string = isset($values['color']['hexadecimal']) ? $values['color']['hexadecimal'] : $values['color'];
  $this
    ->setHexadecimal($color_string, $notify);
  $service = \Drupal::service('colorapi.service');
  $this
    ->setRed($service
    ->hexToRgb($color_string, 'red'), $notify);
  $this
    ->setGreen($service
    ->hexToRgb($color_string, 'green'), $notify);
  $this
    ->setBlue($service
    ->hexToRgb($color_string, 'blue'), $notify);
}