-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
@@ -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'] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Tests are actually failing and html output should be tested as well IMO. |
3f6ca42
to
7504dde
Compare
What happens when It looks like |
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
af698a0
to
5eac83c
Compare
5eac83c
to
4361034
Compare
4361034
to
2a972f3
Compare
There might be some options not meaningful if the widget is |
@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 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, |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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
.
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']) { |
There was a problem hiding this comment.
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 : 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). |
ok, so let's close this one then, right? |
Agreed! Let's keep the original issue open to discuss a better way to get this moving forward. |
Yep 👍 |
Some tests are failing after rebase from 2.x to 3.x branch.