You are here

public function PriceItem::setValue in Price 3.0.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. 2.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

1 call to PriceItem::setValue()
PriceModifiedItem::setValue in src/Plugin/Field/FieldType/PriceModifiedItem.php
Sets the data value.
1 method overrides PriceItem::setValue()
PriceModifiedItem::setValue in src/Plugin/Field/FieldType/PriceModifiedItem.php
Sets the data value.

File

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

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