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
[Form] Cannot use object of type Closure as array #33188
Comments
Does this happen with 4.3 too? If so, could your create a small example application that allows to reproduce? |
According to code I guess it does. I will try to create a reproducer when I have time. |
Why do you pass the |
Yes, I fixed that, but it still feels like BC break. |
Even if passing the parent/resolved https://symfony.com/doc/current/reference/forms/types/form.html#empty-data:
https://symfony.com/doc/current/form/use_empty_data.html#option-2-provide-a-closure:
So the above example should also work for TimeType, isn't it? |
Yeah, seems so. |
symfony/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php Lines 77 to 81 in ef0119a
As we can't invoke the if ($emptyData instanceof \Closure) {
$hourOptions['empty_data'] = static function (FormInterface $form) use ($emptyData) {
$emptyData = $emptyData($form->getParent());
return isset($emptyData['hour']) ? $emptyData['hour'] : '';
};
} // elseif ... @umpirsky would you like to give it a try? (bugfix in 3.4 branch) |
Sorry, can't work on it now, it must wait. |
See #34123 |
…/Time form types (yceruto) This PR was merged into the 3.4 branch. Discussion ---------- [Form] Fix handling of empty_data's \Closure value in Date/Time form types | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #33188 | License | MIT | Doc PR | - Basically this would solve the posibility to pass a `\Closure` to the `empty_data` option for Date/Time form types. > https://symfony.com/doc/current/reference/forms/types/form.html#empty-data > If a form is compound, you can set empty_data as an array, object or **closure**. See the [How to Configure empty Data](https://symfony.com/doc/current/form/use_empty_data.html) for a Form Class article for more details about these options. Also related to #29182 Commits ------- 4939f0e Fix handling of empty_data's \Closure value in Date/Time form types
Symfony version(s) affected: 4.2.11
How to reproduce
Have type defined like this:
You get this error when creating the form:
The problem is passing options to
$builder->add('time', TimeType::class, $options)
which carries:This used to work in 4.1
Additional context
Suspected changeset #29182.
The text was updated successfully, but these errors were encountered: