Extending¶
The module defines no hooks, events, services or permissions for other modules to use. It provides two helper functions and three plugins.
Helper functions¶
currency_field_currencies()¶
Returns the full list from currencies.yml: current entries first, then withdrawn ones. Each entry is an array with these keys:
| Key | Example | Notes |
|---|---|---|
Entity |
PERU |
Country or organization, upper case as published |
Currency |
Sol |
Currency name |
AlphabeticCode |
PEN |
|
NumericCode |
'604' |
Three-digit string, NULL for a few historic entries |
MinorUnit |
2 |
Integer, or NULL where ISO gives "N.A." and for withdrawn entries |
WithdrawalDate |
NULL |
YYYY-MM or a range for withdrawn entries, NULL for current ones |
A code appears once per entity that uses it, so EUR has dozens of entries. The list is cached in the default cache bin, keyed by the file's modification time.
currency_field_currency_options($blank, $format, $include_withdrawn)¶
Returns options keyed and labelled by two columns of the list.
// ['AFN' => 'Afghani', 'EUR' => 'Euro', ...], current currencies only.
$options = currency_field_currency_options(FALSE, ['AlphabeticCode' => 'Currency'], FALSE);
// Keyed by numeric code.
$options = currency_field_currency_options(FALSE, ['NumericCode' => 'AlphabeticCode']);
$blank: unused, kept for backward compatibility.$format: a one-element array mapping the key column to the label column. Defaults to['AlphabeticCode' => 'Currency'].$include_withdrawn: whether to include withdrawn currencies. Defaults toTRUE.
When several entries share a key, the last current entry gives the label, and a withdrawn entry is used only when no current entry has that key. Entity labels are title-cased.
Plugins¶
| Plugin type | ID | Class |
|---|---|---|
| Field type | currency_field |
Drupal\currency_field\Plugin\Field\FieldType\CurrencyField |
| Field widget | currency_widget |
Drupal\currency_field\Plugin\Field\FieldWidget\CurrencyWidget |
| Field formatter | currency_formatter |
Drupal\currency_field\Plugin\Field\FieldFormatter\CurrencyFormatter |
Other modules can provide widgets and formatters for currency_field by listing it in their plugin's field_types, or alter these plugins with hook_field_widget_info_alter() and hook_field_formatter_info_alter().
Validation constraint¶
CurrencyField::getConstraints() adds a ComplexData constraint with AllowedValues on the value property. To accept other codes, for example cryptocurrencies, alter the field type's class with hook_field_info_alter() and override getConstraints() in a subclass.
Configuration schema¶
| Schema type | Keys |
|---|---|
field.storage_settings.currency_field |
display: AlphabeticCode, Entity or Currency |
field.value.currency_field |
value: the default code |
field.formatter.settings.currency_formatter |
display: AlphabeticCode, Entity or Currency |