You are here

public function PriceItem::setValue in Price 2.x

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldType/PriceItem.php \Drupal\price\Plugin\Field\FieldType\PriceItem::setValue()
  2. 3.x src/Plugin/Field/FieldType/PriceItem.php \Drupal\price\Plugin\Field\FieldType\PriceItem::setValue()
  3. 2.0.x src/Plugin/Field/FieldType/PriceItem.php \Drupal\price\Plugin\Field\FieldType\PriceItem::setValue()
  4. 3.0.x src/Plugin/Field/FieldType/PriceItem.php \Drupal\price\Plugin\Field\FieldType\PriceItem::setValue()

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

Parameters

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

bool $notify: (optional) Whether to notify the parent object of the change. Defaults to TRUE. If a property is updated from a parent object, set it to FALSE to avoid being notified again.

Overrides FieldItemBase::setValue

File

src/Plugin/Field/FieldType/PriceItem.php, line 152

Class

PriceItem
Plugin implementation of the 'price' field type.

Namespace

Drupal\price\Plugin\Field\FieldType

Code

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

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