phone-number-bundle icon indicating copy to clipboard operation
phone-number-bundle copied to clipboard

short country name

Open thoroc opened this issue 8 years ago • 2 comments

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

thoroc avatar Jun 26 '16 15:06 thoroc

This could be solved by merging the following PR: https://github.com/misd-service-development/phone-number-bundle/pull/90

thoroc avatar Jun 28 '16 07:06 thoroc

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'],
        ...
    ])
;

thoroc avatar Jul 04 '16 14:07 thoroc