You are here

public function PriceNumericField::render in Commerce Reporting 8

Renders the field.

Parameters

\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.

Return value

string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.

Overrides NumericField::render

File

src/Plugin/views/field/PriceNumericField.php, line 34

Class

PriceNumericField
Aggregated price fields have their handler swapped to use this handler in commerce_reports_views_pre_build.

Namespace

Drupal\commerce_reports\Plugin\views\field

Code

public function render(ResultRow $values) {
  $number = $this
    ->getValue($values, $this->field . '_number');
  $currency_code = $this
    ->getValue($values, $this->field . '_currency_code');
  if (!$currency_code) {
    return parent::render($values);
  }
  $currency = Currency::load($currency_code);
  if (!$currency) {
    return parent::render($values);
  }
  $formatter = \Drupal::getContainer()
    ->get('commerce_price.number_formatter_factory')
    ->createInstance();
  return $formatter
    ->formatCurrency($number, $currency);
}