public static function Country::getDefaultCountry in Address 8
Gets the default country based on the available countries.
Used as a helper by parent form elements (Address, ZoneTerritory).
Parameters
array $available_countries: The available countries, an array of country codes.
Return value
string The default country.
2 calls to Country::getDefaultCountry()
- Address::valueCallback in src/
Element/ Address.php - Determines how user input is mapped to an element's #value property.
- ZoneTerritory::valueCallback in src/
Element/ ZoneTerritory.php - Determines how user input is mapped to an element's #value property.
File
- src/
Element/ Country.php, line 135
Class
- Country
- Provides a country form element.
Namespace
Drupal\address\ElementCode
public static function getDefaultCountry(array $available_countries = []) {
$full_country_list = \Drupal::service('address.country_repository')
->getList();
$country_list = $full_country_list;
if (!empty($available_countries)) {
$available_countries = array_combine($available_countries, $available_countries);
$country_list = array_intersect_key($country_list, $available_countries);
}
$default_country = key($country_list);
return $default_country;
}