You are here

protected function Amount::getCurrency in Currency 8.3

Loads the Currency for this field.

Parameters

\Drupal\views\ResultRow $values: A values object as received by $this->render().

Return value

\Drupal\currency\Entity\CurrencyInterface

Throws

\RuntimeException

1 call to Amount::getCurrency()
Amount::render in src/Plugin/views/field/Amount.php
Renders the field.

File

src/Plugin/views/field/Amount.php, line 154

Class

Amount
A Views field handler for currency amounts.

Namespace

Drupal\currency\Plugin\views\field

Code

protected function getCurrency(ResultRow $values) {
  $currency = NULL;
  if ($this->definition['currency_code_field']) {
    $currency_code = $this
      ->getValue($values, 'currency_code_field');
    if ($currency_code) {
      $currency = $this->currencyStorage
        ->load($currency_code);
    }
  }
  if (!$currency && $this->definition['currency_code']) {
    $currency = $this->currencyStorage
      ->load($this->definition['currency_code']);
  }
  if (!$currency) {
    $currency = $this->currencyStorage
      ->load('XXX');
  }
  if (!$currency) {
    throw new \RuntimeException('Could not load currency XXX.');
  }
  return $currency;
}