public function MobileNumberUtil::getCountryOptions in Mobile Number 8
Same name and namespace in other branches
- 2.0.x src/MobileNumberUtil.php \Drupal\mobile_number\MobileNumberUtil::getCountryOptions()
Get all supported countries.
Parameters
array $filter: Limit options to the ones in the filter. (Eg. ['IL' => 'IL', 'US' => 'US'].
bool $show_country_names: Whether to show full country name instead of country codes.
Return value
array Array of options, with country code as keys. (Eg. ['IL' => 'IL (+972)'])
Overrides MobileNumberUtilInterface::getCountryOptions
File
- src/
MobileNumberUtil.php, line 195
Class
- MobileNumberUtil
- Turns a render array into a HTML string.
Namespace
Drupal\mobile_numberCode
public function getCountryOptions($filter = [], $show_country_names = FALSE) {
$libUtil = $this->libUtil;
$regions = $libUtil
->getSupportedRegions();
$countries = [];
foreach ($regions as $region => $country) {
$code = $libUtil
->getCountryCodeForRegion($country);
if (!$filter || !empty($filter[$country])) {
$name = $this
->getCountryName($country);
$countries[$country] = $show_country_names && $name ? "{$name} (+{$code})" : "{$country} (+{$code})";
}
}
asort($countries);
return $countries;
}