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.

Files: 
CommentFileSizeAuthor
#11 formerrorskey-1432732-11.patch980 bytesJorrit
PASSED: [[SimpleTest]]: [MySQL] 39,131 pass(es).
[ View ]
#4 formerrorskey-1432732-4.patch992 bytesJorrit
PASSED: [[SimpleTest]]: [MySQL] 36,701 pass(es).
[ View ]
#1 field-form-error-reporting-fallback-is-wrong-1432732-1.patch588 bytesB-Prod
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch field-form-error-reporting-fallback-is-wrong-1432732-1.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Comments

Status:Active» Needs review
StatusFileSize
new588 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch field-form-error-reporting-fallback-is-wrong-1432732-1.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

The patch below modifies the fallback error reporting, according to the specifications of the FieldValidationException class, where the errors array is clearly defined as:

An array of field validation errors, keyed by field name and
delta that contains two keys:

  • 'error': A machine-readable error code string, prefixed by the field module name. A field widget may use this code to decide how to report the error.
  • 'message': A human-readable error message such as to be passed to form_error() for the appropriate form element.

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.

Status:Needs review» Reviewed & tested by the community

I 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.

Status:Needs review» Needs work

The 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.

Version:7.x-dev» 8.x-dev
Status:Reviewed & tested by the community» Needs review
StatusFileSize
new992 bytes
PASSED: [[SimpleTest]]: [MySQL] 36,701 pass(es).
[ View ]

Updated the patch for Drupal 8.

Status:Needs work» Reviewed & tested by the community

yup

Status:Reviewed & tested by the community» Fixed

Committed to 8.x. Thanks.

Version:8.x-dev» 7.x-dev
Status:Fixed» Patch (to be ported)

This was for Drupal 7 too, wasn't it?

Yes, patch #1 is for Drupal 7.

Status:Patch (to be ported)» Needs review

Status:Needs review» Needs work

Looks like the patch no longer applies.

Status:Needs work» Needs review
StatusFileSize
new980 bytes
PASSED: [[SimpleTest]]: [MySQL] 39,131 pass(es).
[ View ]

Here you go.

Status:Needs review» Reviewed & tested by the community

yup again

Status:Reviewed & tested by the community» Fixed

Thanks for the commit.

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.