phone-number-bundle
phone-number-bundle copied to clipboard
short country name
Hi,
I couldn't find it in the docs: How do I display the country code and identification in the drop down when choosing a widget 'country_choice' ?
I know this could be changed in the Misd\PhoneNumberBundle\Form\Type\PhoneNumberType
at line 68 as follow:
foreach (Intl::getRegionBundle()->getCountryNames() as $region => $name) {
if (false === isset($countries[$region])) {
continue;
}
$countryChoices[sprintf('%s (+%s)', $region, $countries[$region])] = $region;
}
But I was wondering if there isn't a cleaner way to do this
~thoroc
This could be solved by merging the following PR: https://github.com/misd-service-development/phone-number-bundle/pull/90
for ref, once the PR is merged, the label can be used as follow:
$builder
->add('telephoneNumber', PhoneNumberType::class, [
'widget' => PhoneNumberType::WIDGET_COUNTRY_CHOICE,
'country_choices' => ['DE', 'CH', 'AT'],
'country_widget_label' => function($countries, $name, $region){
return sprintf('%s (+%s)', $region, $countries[$region]);
},
'preferred_country_choices' => ['DE'],
...
])
;