public function AvailableCountriesTrait::getAvailableCountries in Address 8
Gets the available countries for the current field.
Return value
array A list of country codes.
2 calls to AvailableCountriesTrait::getAvailableCountries()
- AddressItem::getConstraints in src/
Plugin/ Field/ FieldType/ AddressItem.php - Gets a list of validation constraints.
- CountryItem::getConstraints in src/
Plugin/ Field/ FieldType/ CountryItem.php - Gets a list of validation constraints.
File
- src/
Plugin/ Field/ FieldType/ AvailableCountriesTrait.php, line 65
Class
- AvailableCountriesTrait
- Allows field types to limit the available countries.
Namespace
Drupal\address\Plugin\Field\FieldTypeCode
public function getAvailableCountries() {
// Alter the list once per field, instead of once per field delta.
$field_definition = $this
->getFieldDefinition();
$definition_id = spl_object_hash($field_definition);
if (!isset(static::$availableCountries[$definition_id])) {
$available_countries = array_filter($this
->getSetting('available_countries'));
$event_dispatcher = \Drupal::service('event_dispatcher');
$event = new AvailableCountriesEvent($available_countries, $field_definition);
$event_dispatcher
->dispatch(AddressEvents::AVAILABLE_COUNTRIES, $event);
static::$availableCountries[$definition_id] = $event
->getAvailableCountries();
}
return static::$availableCountries[$definition_id];
}