You are here

public function FormHelper::getCurrencyOptions in Currency 8.3

Returns an options list of all currencies.

Parameters

\Drupal\currency\Entity\CurrencyInterface[]|null $currencies: An array of currencies to limit the options by, or NULL to allow all currencies to be selected.

Return value

array Keys are currency codes. Values are human-readable currency labels.

Overrides FormHelperInterface::getCurrencyOptions

File

src/FormHelper.php, line 46

Class

FormHelper
Provides form helpers.

Namespace

Drupal\currency

Code

public function getCurrencyOptions(array $currencies = NULL) {
  $options = array();

  /** @var \Drupal\currency\Entity\CurrencyInterface[] $currencies */
  if (is_null($currencies)) {
    $currencies = $this->currencyStorage
      ->loadMultiple();
  }
  foreach ($currencies as $currency) {

    // Do not show disabled currencies.
    if ($currency
      ->status()) {
      $options[$currency
        ->id()] = $this
        ->t('@currency_title (@currency_code)', array(
        '@currency_title' => $currency
          ->label(),
        '@currency_code' => $currency
          ->id(),
      ));
    }
  }
  natcasesort($options);
  return $options;
}