You are here

public function MeasurementItem::setValue in Physical Fields 8

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

Parameters

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

Overrides FieldItemBase::setValue

File

src/Plugin/Field/FieldType/MeasurementItem.php, line 95

Class

MeasurementItem
Plugin implementation of the 'physical_measurement' field type.

Namespace

Drupal\physical\Plugin\Field\FieldType

Code

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

  // Allow callers to pass a Measurement value object as the field item value.
  if ($values instanceof Measurement) {
    $measurement = $values;
    $values = [
      'number' => $measurement
        ->getNumber(),
      'unit' => $measurement
        ->getUnit(),
    ];
  }
  parent::setValue($values, $notify);
}