class FormHelper in Currency 8.3
Provides form helpers.
Hierarchy
- class \Drupal\currency\FormHelper implements FormHelperInterface uses StringTranslationTrait
Expanded class hierarchy of FormHelper
1 file declares its use of FormHelper
- FormHelperTest.php in tests/
src/ Unit/ FormHelperTest.php
1 string reference to 'FormHelper'
1 service uses FormHelper
File
- src/
FormHelper.php, line 12
Namespace
Drupal\currencyView source
class FormHelper implements FormHelperInterface {
use StringTranslationTrait;
/**
* The currency storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $currencyStorage;
/**
* The currency locale storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $currencyLocaleStorage;
/**
* Constructs a new instance.
*
* @param \Drupal\Core\StringTranslation\TranslationInterface
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
*/
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;
}
/**
* {@inheritdoc}
*/
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;
}
/**
* {@inheritdoc}
*/
public function getCurrencyLocaleOptions(array $currency_locales = NULL) {
$options = array();
/** @var \Drupal\currency\Entity\CurrencyLocaleInterface[] $currency_locales */
if (is_null($currency_locales)) {
$currency_locales = $this->currencyLocaleStorage
->loadMultiple();
}
foreach ($currency_locales as $currency_locale) {
// Do not show disabled currency locales.
if ($currency_locale
->status()) {
$options[$currency_locale
->id()] = $currency_locale
->label();
}
}
natcasesort($options);
return $options;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FormHelper:: |
protected | property | The currency locale storage. | |
FormHelper:: |
protected | property | The currency storage. | |
FormHelper:: |
public | function |
Returns an options list of all currency locales. Overrides FormHelperInterface:: |
|
FormHelper:: |
public | function |
Returns an options list of all currencies. Overrides FormHelperInterface:: |
|
FormHelper:: |
public | function | Constructs a new instance. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |