Skip to content

[Form] Add choice_translation_locale option for Intl choice types #26825

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 2 commits into from
Apr 22, 2018

Conversation

yceruto
Copy link
Member

@yceruto yceruto commented Apr 5, 2018

Q A
Branch? master (4.1)
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets #26737
License MIT
Doc PR symfony/symfony-docs#...

This PR adds possibility to show the list of elements for a custom locale different to the current one and proposes also deprecate the ChoiceLoaderInterface implementation from all of them, moving it to a separate class.

See related issue #26737 for full description and use-case.

After:

$formBuilder->add('country', CountryType::class, [
    'choice_translation_locale' => 'es',
]);

Alternative of #23629

TODO:

  • Update UPGRADE-*.md and src/**/CHANGELOG.md files.
  • Add some tests.

@yceruto yceruto changed the title Add choice_translation_locale option for Intl choice types [Form] Add choice_translation_locale option for Intl choice types Apr 5, 2018
@yceruto yceruto force-pushed the choice_translation_locale branch from c81bf25 to b26715f Compare April 5, 2018 21:37
@ogizanagi ogizanagi added this to the 4.2 milestone Apr 5, 2018
@ogizanagi ogizanagi added the Form label Apr 5, 2018
@yceruto yceruto force-pushed the choice_translation_locale branch from b26715f to 1480bbd Compare April 5, 2018 22:18
// BC layer
$self = clone $this;
$self->choiceLoader = $choiceLoader;

Copy link
Member Author

Choose a reason for hiding this comment

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

Instead of deprecating each ChoiceLoaderInterface methods (trigerring a lot of messages) shouldn't be enough just one here? deprecating the usage of this form type as choice loader? wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we always return the new loader here and just add deprecations to the ChoiceLoaderInterface's methods without modifying them? We indeed target to remove the ChoiceLoaderInterface from all of these types, right?

Copy link
Member Author

@yceruto yceruto Apr 8, 2018

Choose a reason for hiding this comment

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

mmh.. I guess that was what we did in https://github.com/symfony/symfony/pull/23648/files#diff-c6198934d4f35bc102ff362d40b71285R61, but isn't it a BC break?

I mean, if we return the new loader now then, we're ignoring any custom behavior for someone overriding loadChoiceList() method without previous advice, no? ping @ro0NL ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it's a pragmatic choice; switching an implementation detail. Technically no API was broken 😅

Maybe to overcome preserve the legacy loader somehow, like return new CallbackLegacyChoiceLoader($callable, $this).

we're ignoring any custom behavior for someone overriding loadChoiceList()

Im really not sure how big an issue this is, in practice. In theory you're right.

Copy link
Contributor

Choose a reason for hiding this comment

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

That way you can check if a API method is overridden on the legacy loader and deprecate from there, while keep calling it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @ro0NL. Not sure it is worth it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree, in that case I prefer @ro0NL's version, I did the changes, thanks!

Copy link
Contributor

@ogizanagi ogizanagi left a comment

Choose a reason for hiding this comment

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

Thanks for taking care of this @yceruto :)

use Symfony\Component\OptionsResolver\OptionsResolver;

class CountryType extends AbstractType implements ChoiceLoaderInterface
{
/**
* Country loaded choice list.
* BC layer.
Copy link
Contributor

Choose a reason for hiding this comment

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

By marking it @deprecated instead, even if it's private, would help a bit when reading these classes from an IDE as the property usages in this class will be striked out.

// BC layer
$self = clone $this;
$self->choiceLoader = $choiceLoader;

Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we always return the new loader here and just add deprecations to the ChoiceLoaderInterface's methods without modifying them? We indeed target to remove the ChoiceLoaderInterface from all of these types, right?

@yceruto yceruto force-pushed the choice_translation_locale branch 2 times, most recently from b4c0658 to 59d4d00 Compare April 8, 2018 00:29
@yceruto
Copy link
Member Author

yceruto commented Apr 8, 2018

@ogizanagi thank you for this review.

Status: Waiting consensus on depreciation path :)
Status: Needs Work

@yceruto
Copy link
Member Author

yceruto commented Apr 8, 2018

Status: Needs Review

@yceruto yceruto force-pushed the choice_translation_locale branch from bbc7834 to a69b31f Compare April 9, 2018 11:02
@yceruto yceruto force-pushed the choice_translation_locale branch from a69b31f to a4797ac Compare April 18, 2018 02:59
@yceruto
Copy link
Member Author

yceruto commented Apr 18, 2018

Just squashing commits, ready on my side.

Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

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

small CS change needed

*/
public function loadChoiceList($value = null)
{
@trigger_error(sprintf('Method "%s" is deprecated since Symfony 4.2. Use "choice_loader" option instead.', __METHOD__), E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

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

I prefer one sentence for deprecations: ... since Symfony 4.2, use ...

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

UPGRADE-4.2.md Outdated
Form
----

* Deprecated `ChoiceLoaderInterface` implementation in `CountryType`, `LanguageType`, `LocaleType` and `CurrencyType`. Use the "choice_loader" option instead.
Copy link
Member

Choose a reason for hiding this comment

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

"choice_loader" should be enclosed by backticks too

Copy link
Member

Choose a reason for hiding this comment

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

Deprecated the ChoiceLoaderInterface implementation [...]

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed, thank you.

use Symfony\Component\OptionsResolver\OptionsResolver;

class CountryType extends AbstractType implements ChoiceLoaderInterface
class CountryType extends AbstractType
Copy link
Member

Choose a reason for hiding this comment

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

I would not drop the implements here. Technically, that's a BC break.

Copy link
Member Author

Choose a reason for hiding this comment

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

Reverted.

@yceruto yceruto force-pushed the choice_translation_locale branch 2 times, most recently from 82381e4 to e250dfa Compare April 20, 2018 15:41
@yceruto
Copy link
Member Author

yceruto commented Apr 20, 2018

Done.

@fabpot fabpot force-pushed the choice_translation_locale branch from 3f197b6 to 9592fa6 Compare April 22, 2018 06:17
@fabpot fabpot modified the milestones: next, 4.1 Apr 22, 2018
@fabpot
Copy link
Member

fabpot commented Apr 22, 2018

Thank you @yceruto.

@fabpot fabpot merged commit 9592fa6 into symfony:master Apr 22, 2018
fabpot added a commit that referenced this pull request Apr 22, 2018
…hoice types (yceruto, fabpot)

This PR was merged into the 4.1-dev branch.

Discussion
----------

[Form] Add choice_translation_locale option for Intl choice types

| Q             | A
| ------------- | ---
| Branch?       | master (4.2)
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #26737
| License       | MIT
| Doc PR        | symfony/symfony-docs#...

This PR adds possibility to show the list of elements for a custom locale different to the current one and proposes also deprecate the `ChoiceLoaderInterface` implementation from all of them, moving it to a separate class.

See related issue #26737 for full description and use-case.

After:
```php
$formBuilder->add('country', CountryType::class, [
    'choice_translation_locale' => 'es',
]);
```

Alternative of #23629

TODO:

- [x] Update `UPGRADE-*.md` and `src/**/CHANGELOG.md` files.
- [x] Add some tests.

Commits
-------

9592fa6 moved feature to 4.1
e250dfa Add choice_translation_locale option for Intl choice types
@yceruto yceruto deleted the choice_translation_locale branch April 22, 2018 16:13
@fabpot fabpot mentioned this pull request May 7, 2018
symfony-splitter pushed a commit to symfony/form that referenced this pull request May 29, 2019
…nterface in intl forms (yceruto)

This PR was merged into the 5.0-dev branch.

Discussion
----------

[Form] Remove deprecated implementation of ChoiceLoaderInterface in intl forms

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

See previous PR symfony/symfony#26825 (4.1)

Commits
-------

b22cbf41c0 Remove deprecated implementation of ChoiceLoaderInterface in intl forms
nicolas-grekas added a commit that referenced this pull request May 29, 2019
…nterface in intl forms (yceruto)

This PR was merged into the 5.0-dev branch.

Discussion
----------

[Form] Remove deprecated implementation of ChoiceLoaderInterface in intl forms

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

See previous PR #26825 (4.1)

Commits
-------

b22cbf4 Remove deprecated implementation of ChoiceLoaderInterface in intl forms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants