In file_field_widget_value(), the second argument has a default value, but the third does not. Remove this default value.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | drupal-remove_optional_not_at_end-3018815-2-D7.patch | 615 bytes | liam morland |
In file_field_widget_value(), the second argument has a default value, but the third does not. Remove this default value.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | drupal-remove_optional_not_at_end-3018815-2-D7.patch | 615 bytes | liam morland |
Comments
Comment #2
liam morlandComment #3
avpadernoThe documentation for the #value callback shows different paraments for the callback.
Maybe the arguments should be changed to be
$element, $input = FALSE, $form_state = array(), instead of$element, $input, $form_state.Comment #4
avpadernoNotice that Drupal 8 uses
$element, $input, FormStateInterface $form_statebecause the last argument cannot take a default value that wouldn't cause any error message without the code checking its value. (I imagine what would happen with$element, $input, FormStateInterface $form_state = NULLwhen the callback receives the default argument.)In Drupal 7, there isn't that problem, since
$form_stateis an array, and an empty array as default value does make sense.Comment #5
liam morlandI'm not sure file_field_widget_value() would be OK with getting an empty array instead of an actual form state. file_managed_file_value() might not work with that. Is there any use for calling file_field_widget_value() with only $element as an argument?
Comment #6
avpadernoActually, it seems the default value for the second parameter is only used to show/remember that FALSE could be passed as second argument.
That should not be the purpose of default values for parameters. The documentation for the value callback should be changed to show no default values are given for the callback parameters.
Comment #7
avpadernoInside the file.module file there is also
file_managed_file_value(), for which the parameters are&$element, $input = FALSE, $form_state = NULL.Those aren't even the parameters described in the documentation, and they don't make sense, as the value callback will probably never get a null form state, since the value callbacks are called from a function (
_form_builder_handle_input_element()) that gets a valid$form_state(and not an empty array orNULL) fromform_builder().Comment #8
avpadernoAnd to make this more confusing, there are value callbacks that just declare two parameters, like
form_type_token_value(). (Truly, this happens for all theform_type_*_value() functions.)Comment #9
poker10 commentedThis was fixed in #3156847: [PHP 8] Parameter order fixes, as it was causing PHP 8 deprecation message. I have added credits for your effort to the mentioned issue.