-
-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) | |
$choiceList = $this->createChoiceList($options); | ||
$builder->setAttribute('choice_list', $choiceList); | ||
|
||
if ($options['expanded'] && !in_array($options['widget'], array('text', 'hidden'))) { | ||
if ($options['expanded'] && !in_array($options['widget'], array('text', 'hidden'), true)) { | ||
$builder->setDataMapper($options['multiple'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be What is the point of having
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For |
||
? new CheckboxListMapper($choiceList) | ||
: new RadioListMapper($choiceList)); | ||
|
@@ -151,7 +151,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) | |
$builder->addViewTransformer(new ChoicesToValuesTransformer($choiceList)); | ||
|
||
// for "text" / "hidden" widget, view data uses a delimiter | ||
if (in_array($options['widget'], array('text', 'hidden'))) { | ||
if (in_array($options['widget'], array('text', 'hidden'), true)) { | ||
$builder->addViewTransformer(new ValuesToStringTransformer($options['delimiter'], $options['trim'])); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This implementation is wrong IMO since transformers may be executed in the right order for transformation but not for reversing transformation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure I get what you mean, Symfony will chain them in the correct order automatically depending on the direction (view to norm or norm to view). |
||
} else { | ||
|
@@ -195,7 +195,7 @@ public function buildView(FormView $view, FormInterface $form, array $options) | |
'choice_translation_domain' => $choiceTranslationDomain, | ||
)); | ||
|
||
if (in_array($options['widget'], array('text', 'hidden'))) { | ||
if (in_array($options['widget'], array('text', 'hidden'), true)) { | ||
return; | ||
} | ||
|
||
|
@@ -237,7 +237,7 @@ public function buildView(FormView $view, FormInterface $form, array $options) | |
*/ | ||
public function finishView(FormView $view, FormInterface $form, array $options) | ||
{ | ||
if (in_array($options['widget'], array('text', 'hidden'))) { | ||
if (in_array($options['widget'], array('text', 'hidden'), true)) { | ||
return; | ||
} | ||
|
||
|
@@ -318,8 +318,8 @@ public function configureOptions(OptionsResolver $resolver) | |
}; | ||
|
||
$multipleNormalizer = function (Options $options, $multiple) { | ||
if (in_array($options['widget'], array('radio', 'checkbox'))) { | ||
return 'checkbox' == $options['widget']; | ||
if (in_array($options['widget'], array('radio', 'checkbox'), true)) { | ||
return 'checkbox' === $options['widget']; | ||
} | ||
|
||
return $multiple; | ||
|
@@ -332,7 +332,7 @@ public function configureOptions(OptionsResolver $resolver) | |
$expanded = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is not need if you cast return to bool :
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 commentThe 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 |
||
} | ||
|
||
return in_array($options['widget'], array('radio', 'checkbox')) ?: $expanded; | ||
return in_array($options['widget'], array('radio', 'checkbox'), true) ?: $expanded; | ||
}; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could have only one normalizer : $expandedNormalizer = function (Options $options, $expanded) {
// trigger error
return 'expanded' === $options['widget'];
} Anyway it should be : $expandedNomalizer = function (Options $options, $expanded) {
if (null !== $expanded) {
@trigger_error('The "expanded" option is deprecated since version 3.1 for internal use only. You should use "widget" option with "radio" or "checkbox" instead.', E_USER_DEPRECATED);
}
return in_array($options['widget'], array('radio', 'checkbox'));
}; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as discussed previously, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no need to handle you could write : $expandedNomalizer = function (Options $options, $expanded) {
if (null !== $expanded) {
@trigger_error('The "expanded" option is deprecated since version 3.1 for internal use only. You should use "widget" option with "radio" or "checkbox" instead.', E_USER_DEPRECATED);
}
return 'select' === $options['widget'] ? false : (in_array($options['widget'], array('radio', 'checkbox')) ?: $expanded);
}; only if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The goal of this normalizer is to handle |
||
$resolver->setDefaults(array( | ||
|
@@ -376,6 +376,7 @@ public function configureOptions(OptionsResolver $resolver) | |
$resolver->setAllowedTypes('choice_attr', array('null', 'array', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath')); | ||
$resolver->setAllowedTypes('preferred_choices', array('array', '\Traversable', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath')); | ||
$resolver->setAllowedTypes('group_by', array('null', 'array', '\Traversable', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath')); | ||
$resolver->setAllowedValues('widget', array(null, 'hidden', 'text', 'select', 'checkbox', '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.
hidden_widget
andform_widget_simple
never get avalue
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.
see https://github.com/symfony/form/blob/master/Extension/Core/Type/FormType.php#L89