Skip to content
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

feat: Add a feature to change country display format in form #95

Merged
merged 6 commits into from
Dec 19, 2022

Conversation

nicolassing
Copy link

No description provided.

@@ -128,6 +132,7 @@ public function configureOptions(OptionsResolver $resolver)
'by_reference' => false,
'error_bubbling' => false,
'country_choices' => [],
'country_display_type' => self::DISPLAY_COUNTRY_FULL,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a break, we currently use short format, isn't it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nop, currently we use "France (+33)" the "FULL" format

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad

@@ -61,12 +64,13 @@ public function buildForm(FormBuilderInterface $builder, array $options)

$countryChoices = [];

foreach (Countries::getNames() as $region => $name) {
if (false === isset($countries[$region])) {
foreach ($countries as $regionCode => $countryCode) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? It's not equivalent to what was here before. Therefore it potentially breaks the compatibility.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The results is almost the same. I made this change to keep the order given in the countries configuration entry.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not mistaken, the performances are not the same this way because before the data was loaded and browsed only once in the buffer of the component while now we have it as many times as countries support x2 (exists & getName)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right ! Not sure its a big deal. Let me check :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not be so convinced. I would like to have a verification on this before

Copy link
Collaborator

@Nek- Nek- Dec 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The performance overhead is actually small. But I'm surprised there's indeed a topic here. That said, a solution can be quickly found here:

if (!Countries::exists($regionCode))

could be changed easily with

$intlCountries = Countries::getNames();
// and later
if (!isset($intlCountries[$regionCode]))

(and Countries::getName($regionCode) by $intlCountries[$regionCode])

Co-authored-by: Maxime Veber <[email protected]>
@nicolassing nicolassing requested a review from Nek- November 22, 2021 17:22
@nicolassing
Copy link
Author

Hi !
If someone want to discuss about this PR, let me know :)

@Nek-
Copy link
Collaborator

Nek- commented Dec 2, 2022

Hello @nicolassing sorry for not taking the time to have a look, and thank you very much for your patience. This feature is nice and can be merged.

Can you add the (little) optimization I suggested?

Side note: please rebase your PR and squash your commit as soon as #134 is merged.

@nicolassing
Copy link
Author

Hello @nicolassing sorry for not taking the time to have a look, and thank you very much for your patience. This feature is nice and can be merged.

Can you add the (little) optimization I suggested?

Side note: please rebase your PR and squash your commit as soon as #134 is merged.

I'll try to work on this week !
Thanks :)

@Nek- Nek- merged commit b07b919 into odolbeau:master Dec 19, 2022
@Nek-
Copy link
Collaborator

Nek- commented Dec 19, 2022

Thank you very much @nicolassing !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants