Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
In Drupal\file\Plugin\Field\FieldWidget\FileWidget::value(), $input argument as default value. $input is the second argument and the third $form_state is required.
FileWidget::value() is called thanks to #value_callback in FormBuilder::handleInputElement() and $input is always setted. In every cases, not settings $input will cause error since the third argument is required.
Default value for $input is useless and should be removed.
Proposed resolution
Remove default value from $input argument.
Comment | File | Size | Author |
---|---|---|---|
#7 | interdiff-2-7.txt | 796 bytes | rosinegrean |
#7 | default_value_in-2810903-7.patch | 1.58 KB | rosinegrean |
#2 | default_value_in-2810903-2.patch | 1.16 KB | GoZ |
Comments
Comment #2
GoZ CreditAttribution: GoZ at Centarro commentedComment #4
GoZ CreditAttribution: GoZ at Centarro commentedComment #5
B31 CreditAttribution: B31 commentedComment #6
xjmThanks @GoZ, good find!
This exact bug is also found in
color.module
:Let's fix that too. I'd also suggest blaming the declaration to see how and when this bug was introduced, and make sure there is not another bug because of it. Thanks!
Comment #7
rosinegrean CreditAttribution: rosinegrean at PitechPlus commentedHello,
Looks like this was done here Move FAPI callbacks for file/image widgets in classes so a long time ago.
I haven't seen in this patch something else buggy.
Here is the updated patch.
Comment #8
GoZ CreditAttribution: GoZ at Centarro commentedComment #10
catchI had a bit of a look further back with git log -S
It was added when file module was originally added to core:
My guess would be the callback originally didn't take $form_state, then it was added on, but it's been that way (albeit moved around over time with different naming) for at least seven years now.
Committed/pushed to 8.3.x, thanks!