public function CountryFieldManager::getSelectableCountries in Country 8
Get array of selectable countries.
If some countries have been selected at the default field settings, allow only those to be selectable. Else, check if any have been selected for the field instance. If none, allow all available countries.
Parameters
\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition object.
Return value
array The array of country names keyed by their ISO2 values.
File
- src/
CountryFieldManager.php, line 43
Class
- CountryFieldManager
- Defines a class for country field management.
Namespace
Drupal\countryCode
public function getSelectableCountries(FieldDefinitionInterface $field_definition) {
$field_definition_countries = $field_definition
->getSetting('selectable_countries');
$field_storage_countries = $field_definition
->getFieldStorageDefinition()
->getSetting('selectable_countries');
$countries = $this->countryManager
->getList();
$allowed = !empty($field_definition_countries) ? $field_definition_countries : $field_storage_countries;
return !empty($allowed) ? array_intersect_key($countries, $allowed) : $countries;
}