Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Form] Added CountryType option for using alpha3 country codes #33791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,19 @@ public function configureOptions(OptionsResolver $resolver)
$resolver->setDefaults([
'choice_loader' => function (Options $options) {
$choiceTranslationLocale = $options['choice_translation_locale'];
$alpha3 = $options['alpha3'];

return new IntlCallbackChoiceLoader(function () use ($choiceTranslationLocale) {
return array_flip(Countries::getNames($choiceTranslationLocale));
return new IntlCallbackChoiceLoader(function () use ($choiceTranslationLocale, $alpha3) {
return array_flip($alpha3 ? Countries::getAlpha3Names($choiceTranslationLocale) : Countries::getNames($choiceTranslationLocale));
});
},
'choice_translation_domain' => false,
'choice_translation_locale' => null,
'alpha3' => false,
creiner marked this conversation as resolved.
Show resolved Hide resolved
]);

$resolver->setAllowedTypes('choice_translation_locale', ['null', 'string']);
$resolver->setAllowedTypes('alpha3', 'bool');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,19 @@ public function configureOptions(OptionsResolver $resolver)
$resolver->setDefaults([
'choice_loader' => function (Options $options) {
$choiceTranslationLocale = $options['choice_translation_locale'];
$alpha3 = $options['alpha3'];

return new IntlCallbackChoiceLoader(function () use ($choiceTranslationLocale) {
return array_flip(Languages::getNames($choiceTranslationLocale));
return new IntlCallbackChoiceLoader(function () use ($choiceTranslationLocale, $alpha3) {
return array_flip($alpha3 ? Languages::getAlpha3Names($choiceTranslationLocale) : Languages::getNames($choiceTranslationLocale));
});
},
'choice_translation_domain' => false,
'choice_translation_locale' => null,
'alpha3' => false,
]);

$resolver->setAllowedTypes('choice_translation_locale', ['null', 'string']);
$resolver->setAllowedTypes('alpha3', 'bool');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,42 @@ public function testChoiceTranslationLocaleOption()
$this->assertContainsEquals(new ChoiceView('MY', 'MY', 'Малайзія'), $choices);
}

public function testAlpha3Option()
creiner marked this conversation as resolved.
Show resolved Hide resolved
{
$choices = $this->factory
->create(static::TESTED_TYPE, null, [
'alpha3' => true,
])
->createView()->vars['choices'];

// Don't check objects for identity
$this->assertContainsEquals(new ChoiceView('DEU', 'DEU', 'Germany'), $choices);
$this->assertContainsEquals(new ChoiceView('GBR', 'GBR', 'United Kingdom'), $choices);
$this->assertContainsEquals(new ChoiceView('USA', 'USA', 'United States'), $choices);
$this->assertContainsEquals(new ChoiceView('FRA', 'FRA', 'France'), $choices);
$this->assertContainsEquals(new ChoiceView('MYS', 'MYS', 'Malaysia'), $choices);
}

/**
* @requires extension intl
*/
public function testChoiceTranslationLocaleAndAlpha3Option()
{
$choices = $this->factory
->create(static::TESTED_TYPE, null, [
'choice_translation_locale' => 'uk',
'alpha3' => true,
])
->createView()->vars['choices'];

// Don't check objects for identity
$this->assertContainsEquals(new ChoiceView('DEU', 'DEU', 'Німеччина'), $choices);
$this->assertContainsEquals(new ChoiceView('GBR', 'GBR', 'Велика Британія'), $choices);
$this->assertContainsEquals(new ChoiceView('USA', 'USA', 'Сполучені Штати'), $choices);
$this->assertContainsEquals(new ChoiceView('FRA', 'FRA', 'Франція'), $choices);
$this->assertContainsEquals(new ChoiceView('MYS', 'MYS', 'Малайзія'), $choices);
}

public function testUnknownCountryIsNotIncluded()
{
$choices = $this->factory->create(static::TESTED_TYPE, 'country')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,40 @@ public function testChoiceTranslationLocaleOption()
$this->assertContainsEquals(new ChoiceView('my', 'my', 'бірманська'), $choices);
}

public function testAlpha3Option()
{
$choices = $this->factory
->create(static::TESTED_TYPE, null, [
'alpha3' => true,
])
->createView()->vars['choices'];

// Don't check objects for identity
$this->assertContainsEquals(new ChoiceView('eng', 'eng', 'English'), $choices);
$this->assertContainsEquals(new ChoiceView('fra', 'fra', 'French'), $choices);
// Burmese has no three letter language code
$this->assertNotContainsEquals(new ChoiceView('my', 'my', 'Burmese'), $choices);
}

/**
* @requires extension intl
*/
public function testChoiceTranslationLocaleAndAlpha3Option()
{
$choices = $this->factory
->create(static::TESTED_TYPE, null, [
'choice_translation_locale' => 'uk',
'alpha3' => true,
])
->createView()->vars['choices'];

// Don't check objects for identity
$this->assertContainsEquals(new ChoiceView('eng', 'eng', 'англійська'), $choices);
$this->assertContainsEquals(new ChoiceView('fra', 'fra', 'французька'), $choices);
// Burmese has no three letter language code
$this->assertNotContainsEquals(new ChoiceView('my', 'my', 'бірманська'), $choices);
}

public function testMultipleLanguagesIsNotIncluded()
{
$choices = $this->factory->create(static::TESTED_TYPE, 'language')
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Form/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": "^7.1.3",
"symfony/event-dispatcher": "^4.3",
"symfony/intl": "^4.3|^5.0",
"symfony/intl": "^4.4|^5.0",
"symfony/options-resolver": "~4.3|^5.0",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-mbstring": "~1.0",
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.