You are here

public function FormattedPrice::getValue in Price 2.x

Same name and namespace in other branches
  1. 2.0.x src/Plugin/DataType/FormattedPrice.php \Drupal\price\Plugin\DataType\FormattedPrice::getValue()

Gets the data value.

Return value

mixed The data value.

Overrides PrimitiveBase::getValue

File

src/Plugin/DataType/FormattedPrice.php, line 21

Class

FormattedPrice
Defines a data type for formatted prices.

Namespace

Drupal\price\Plugin\DataType

Code

public function getValue() {
  $parent = $this
    ->getParent();
  assert($parent instanceof PriceItem);
  $formatted_price = NULL;
  if (!$parent
    ->isEmpty()) {
    $price = $parent
      ->toPrice();
    $currency_formatter = \Drupal::service('price.currency_formatter');
    $formatted_price = $currency_formatter
      ->format($price
      ->getNumber(), $price
      ->getCurrencyCode());
  }
  return $formatted_price;
}