Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Form] Add option widget to ChoiceType #17646

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

Closed
wants to merge 4 commits into from

Conversation

bamarni
Copy link
Contributor

@bamarni bamarni commented Feb 1, 2016

Q A
Bug fix? [no]
New feature? [yes]
BC breaks? [no]
Deprecations? [yes]
Tests pass? [yes]
Fixed tickets #6602
License MIT

Some tests are failing after rebase from 2.x to 3.x branch.

  • fix tests failures because of deprecations
  • fix tests in doctrine bridge
  • some tests are failing in appveyor but seems unrelated

@@ -60,7 +61,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$choiceList = $this->createChoiceList($options);
$builder->setAttribute('choice_list', $choiceList);

if ($options['expanded']) {
if ($options['expanded'] && !in_array($options['widget'], array('text', 'hidden'))) {
$builder->setDataMapper($options['multiple']
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be if ('expanded' === $options['widget'])

What is the point of having checkbox and radio value for widget option if you still have to deal with multiple option ?

widget might have few options like text, hidden, select and expanded

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For checkbox and radio, multiple option is ignored, I had made the same suggestion (see linked PR description) and @webmozart preferred to have more explicit names.

@HeahDude
Copy link
Contributor

HeahDude commented Feb 2, 2016

Tests are actually failing and html output should be tested as well IMO.
Status: Needs Work

@bamarni
Copy link
Contributor Author

bamarni commented Feb 3, 2016

@HeahDude : Thanks for reviewing and testing the feature in this PR. Please also refer to the original discussions in #6602 for more information about what the widget option is about.

There are still some tests failing because of deprecation notices, I'll try to fix them soon.

@HeahDude
Copy link
Contributor

HeahDude commented Feb 3, 2016

What happens when text choice is edited is the form ?

It looks like choice_value and choice_attr are not working well with this widget option.
Especially when using translation, validation is failing.

if (null !== $expanded) {
@trigger_error('The "expanded" option is deprecated since version 3.1 and will be removed in 4.0. You should use "widget" instead.', E_USER_DEPRECATED);
} else {
$expanded = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is not need if you cast return to bool :

return (bool) (in_array($options['widget'], array('radio', 'checkbox'), true) ?: $expanded);

anyway the cast would be done anywhere in this class as it's only a test variable. Then it has to remain internal and not to be removed in 4.0 with the actual implementation IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is so wrong about this normalizer for you to comment on it since days? :D
Handling everything in one line makes it less readable imo.

@bamarni bamarni force-pushed the form-choice-widget branch from af698a0 to 5eac83c Compare February 3, 2016 22:45
@bamarni bamarni force-pushed the form-choice-widget branch from 5eac83c to 4361034 Compare February 4, 2016 17:58
@bamarni bamarni force-pushed the form-choice-widget branch from 4361034 to 2a972f3 Compare February 4, 2016 18:07
@bamarni
Copy link
Contributor Author

bamarni commented Feb 4, 2016

It looks like choice_value and choice_attr are not working well with this widget option.
Especially when using translation, validation is failing.

There might be some options not meaningful if the widget is text, in that case for example attr could be used instead of choice_attr. About translation issues, do you have an example?

@HeahDude
Copy link
Contributor

HeahDude commented Feb 4, 2016

@bamarni I've tried to make a recap on all the past PR you've made because I actually missed some discussions in there ;) I will soon post it on the main issue (will keep you tagged) to stop over commenting this thread because I really think that the actual implementation of text widget is wrong.

You've done a great job so far. It seems that while testing this feature I encountered a bug from 2.7 due to #14050 with entity type, PR is coming :)

@@ -214,7 +214,7 @@ public function testSingleChoice()
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
'multiple' => false,
Copy link
Contributor

Choose a reason for hiding this comment

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

if widget is explicitly set as select, multiple can be omitted too IMO to ease reading.
You should maybe add a test without widget to see it falls back on select.

@@ -841,8 +836,7 @@ public function testSingleChoiceExpandedWithBooleanValue()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', true, array(
'choices' => array('Choice&A' => '1', 'Choice&B' => '0'),
'multiple' => false,
'expanded' => true,
'widget' => 'radio',
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing a legacy test for singleChoiceExpanded without widget option and expanded as true.

@HeahDude
Copy link
Contributor

HeahDude commented Feb 5, 2016

Well sorry for that new wave of comments, but this is quite a big and important refactoring here :)

Tell me if you need some help with the tests !

if (in_array($options['widget'], array('text', 'hidden'), true)) {
return;
}

if ($options['expanded']) {
Copy link
Contributor

Choose a reason for hiding this comment

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

One last comment "for the road" if I may :

You did the change in https://github.com/bamarni/symfony/blob/9ba6a34f64fc063b3bfc8874d6f9300ba8f4c0be/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php#L145

Why not this PR ?

Handling this everywhere in the class (except for choice view vars) is how you can make $options['expanded'] deprecated otherwise it has to be marked internal.

@fabpot
Copy link
Member

fabpot commented Jul 1, 2016

@bamarni What's the status of this PR? How can we move forward. I can see that @HeahDude made a lof of comments, can you review them?

@bamarni
Copy link
Contributor Author

bamarni commented Jul 1, 2016

@fabpot : As I was working on this I noticed the choice type is not the best fit for this feature. @HeahDude also agrees, cf last messages on the original issue.

IMO : While the original design for this feature looks fine in theory, it comes with quite some inconsistencies, special cases to handle, plus the BC break about the basic usage which would affect all users. Here we basically just need a data transformer on top of existing form types (text, hidden).

@fabpot
Copy link
Member

fabpot commented Jul 1, 2016

ok, so let's close this one then, right?

@HeahDude
Copy link
Contributor

HeahDude commented Jul 1, 2016

Agreed! Let's keep the original issue open to discuss a better way to get this moving forward.

@bamarni
Copy link
Contributor Author

bamarni commented Jul 1, 2016

Yep 👍

@bamarni bamarni closed this Jul 1, 2016
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.

5 participants