In the function field_default_form_errors()
(field.form.inc file), the following code is used for widgets that do not implement [widget]_field_widget_error()
function:
form_error($error_element, $error['error']);
On the Drupal API for such function (http://api.drupal.org/api/drupal/modules!field!field.api.php/function/ho...), the given example uses form_error($element['value'], $error['message']);.
So there is a consistency issue there, where in the first case the $error['error']
value is used and in the standard case $error['message']
.
This causes troubles for example in the Field validation module: http://drupal.org/node/1316368.
Comment | File | Size | Author |
---|---|---|---|
#11 | formerrorskey-1432732-11.patch | 980 bytes | Jorrit |
#4 | formerrorskey-1432732-4.patch | 992 bytes | Jorrit |
#1 | field-form-error-reporting-fallback-is-wrong-1432732-1.patch | 588 bytes | B-Prod |
Comments
Comment #1
B-Prod CreditAttribution: B-Prod commentedThe patch below modifies the fallback error reporting, according to the specifications of the
FieldValidationException
class, where the errors array is clearly defined as:Question: is there a specific reason for using the 'error' key (portability? I may miss something)? If so, then the image widget should implement
image_field_widget_error()
function.Comment #2
Jorrit CreditAttribution: Jorrit commentedI agree with this patch entirely. The second argument to
form_error
should be human readable, so$error['message']
should be used, not$error['error']
.The example code of
hook_field_widget_error()
also demonstrates this.Comment #3
Jorrit CreditAttribution: Jorrit commentedThe sample body for
hook_field_widget_error
does contain a bug:$element['value']
should be$element
, I made #1614468: hook_field_widget_error example implementation contains error for that.Also, Drupal 8 also contains this bug so I guess a patch must be made for that version first.
Comment #4
Jorrit CreditAttribution: Jorrit commentedUpdated the patch for Drupal 8.
Comment #5
bleen CreditAttribution: bleen commentedyup
Comment #6
Dries CreditAttribution: Dries commentedCommitted to 8.x. Thanks.
Comment #7
David_Rothstein CreditAttribution: David_Rothstein commentedThis was for Drupal 7 too, wasn't it?
Comment #8
Jorrit CreditAttribution: Jorrit commentedYes, patch #1 is for Drupal 7.
Comment #9
David_Rothstein CreditAttribution: David_Rothstein commented#1: field-form-error-reporting-fallback-is-wrong-1432732-1.patch queued for re-testing.
Comment #10
David_Rothstein CreditAttribution: David_Rothstein commentedLooks like the patch no longer applies.
Comment #11
Jorrit CreditAttribution: Jorrit commentedHere you go.
Comment #12
bleen CreditAttribution: bleen commentedyup again
Comment #13
David_Rothstein CreditAttribution: David_Rothstein commentedCommitted to 7.x - thanks! http://drupalcode.org/project/drupal.git/commit/0e89940
Comment #14
Jorrit CreditAttribution: Jorrit commentedThanks for the commit.