public function FormattedPrice::getValue in Price 2.0.x
Same name and namespace in other branches
- 2.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\DataTypeCode
public function getValue() {
$parent = $this
->getParent();
assert($parent instanceof PriceItem);
$formatted_price = NULL;
if (!$parent
->isEmpty()) {
try {
$price = $parent
->toPrice();
$currency_formatter = \Drupal::service('price.currency_formatter');
$formatted_price = $currency_formatter
->format($price
->getNumber(), $price
->getCurrencyCode());
} catch (\InvalidArgumentException $exception) {
}
}
return $formatted_price;
}