You are here

public function CurrencyImporter::getImportable in Price 8

Same name and namespace in other branches
  1. 3.x src/CurrencyImporter.php \Drupal\price\CurrencyImporter::getImportable()
  2. 2.0.x src/CurrencyImporter.php \Drupal\price\CurrencyImporter::getImportable()
  3. 2.x src/CurrencyImporter.php \Drupal\price\CurrencyImporter::getImportable()
  4. 3.0.x src/CurrencyImporter.php \Drupal\price\CurrencyImporter::getImportable()

Gets a list of importable currencies.

Return value

array An array in the currencyCode => name format.

Overrides CurrencyImporterInterface::getImportable

File

src/CurrencyImporter.php, line 56

Class

CurrencyImporter
Default implementation of the currency importer.

Namespace

Drupal\price

Code

public function getImportable() {
  $imported_currencies = $this->storage
    ->loadMultiple();

  // The getCurrentLanguage() fallback is a workaround for core bug #2684873.
  $language = $this->languageManager
    ->getConfigOverrideLanguage() ?: $this->languageManager
    ->getCurrentLanguage();
  $langcode = $language
    ->getId();
  $all_currencies = $this->externalRepository
    ->getAll($langcode, 'en');
  $importable_currencies = array_diff_key($all_currencies, $imported_currencies);
  $importable_currencies = array_map(function ($currency) {
    return $currency
      ->getName();
  }, $importable_currencies);
  return $importable_currencies;
}