-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Fixed empty data on expanded ChoiceType and FileType #25948
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 all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,10 +27,10 @@ class FileType extends AbstractType | |
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
// Ensure that submitted data is always an uploaded file or an array of some | ||
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use ($options) { | ||
$form = $event->getForm(); | ||
$requestHandler = $form->getConfig()->getRequestHandler(); | ||
$data = null; | ||
|
||
if ($options['multiple']) { | ||
$data = array(); | ||
|
@@ -46,19 +46,16 @@ public function buildForm(FormBuilderInterface $builder, array $options) | |
} | ||
} | ||
|
||
// submitted data for an input file (not required) without choosing any file | ||
if (array(null) === $data || array() === $data) { | ||
// Since the array is never considered empty in the view data format | ||
// on submission, we need to evaluate the configured empty data here | ||
if (array() === $data) { | ||
$emptyData = $form->getConfig()->getEmptyData(); | ||
|
||
$data = is_callable($emptyData) ? call_user_func($emptyData, $form, $data) : $emptyData; | ||
$data = $emptyData instanceof \Closure ? $emptyData($form, $data) : $emptyData; | ||
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. Note that this bug fix was wrong as well by replicating the first. |
||
} | ||
|
||
$event->setData($data); | ||
} elseif (!$requestHandler->isFileUpload($event->getData())) { | ||
$emptyData = $form->getConfig()->getEmptyData(); | ||
|
||
$data = is_callable($emptyData) ? call_user_func($emptyData, $form, $data) : $emptyData; | ||
$event->setData($data); | ||
$event->setData(null); | ||
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. And that this is a BC break introduced in #24993 which does not count as the one which adds a method to the |
||
} | ||
}); | ||
} | ||
|
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.
is
instanceof \Closure
legit instead ofis_callable
(same below?)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 is totally legit and what must be, this is the point of this bug fix. Only a
\Closure
should be considered here, nothing else.The view data can be:
data_class
option)The three of them can be callable:
Deprecating a broken behavior on master does not make any sense to me,
I really think we need to merge this PR as a bug fix, because the previous one was wrong.