FormHelper.php in Currency 8.3
File
src/FormHelper.php
View source
<?php
namespace Drupal\currency;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
class FormHelper implements FormHelperInterface {
use StringTranslationTrait;
protected $currencyStorage;
protected $currencyLocaleStorage;
public function __construct(TranslationInterface $string_translation, EntityTypeManagerInterface $entity_type_manager) {
$this->currencyStorage = $entity_type_manager
->getStorage('currency');
$this->currencyLocaleStorage = $entity_type_manager
->getStorage('currency_locale');
$this->stringTranslation = $string_translation;
}
public function getCurrencyOptions(array $currencies = NULL) {
$options = array();
if (is_null($currencies)) {
$currencies = $this->currencyStorage
->loadMultiple();
}
foreach ($currencies as $currency) {
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;
}
public function getCurrencyLocaleOptions(array $currency_locales = NULL) {
$options = array();
if (is_null($currency_locales)) {
$currency_locales = $this->currencyLocaleStorage
->loadMultiple();
}
foreach ($currency_locales as $currency_locale) {
if ($currency_locale
->status()) {
$options[$currency_locale
->id()] = $currency_locale
->label();
}
}
natcasesort($options);
return $options;
}
}