API page: http://api.drupal.org/api/drupal/modules--field--field.api.php/function/...

I find the documentation for hook_field_validate to be infuriating. The first time I tried implementing this hook, I didn't know how much validation I needed to do – do I need to validate form input lengths to be no greater than the varchar lengths in my hook_field_schema definition (I don't believe I do, since I can just set a value for the #maxlength key in hook_field_widget_form).

The above issue might simply be a result of my inexperience, but the other issue I ran into appears to be more clear-cut. Nowhere in the hook_field_validate documentation does it mention hook_field_widget_error, which is necessary to implement for the message key values to be printed via form_error in place of the error key values found in the $errors[$field['field_name']][$langcode][$delta][] array definition in hook_field_validate. I wasted probably two hours on this (it doesn't help that neither the Drupal 7 Module Development book nor various online documentation I found mention hook_field_widget_error); am I missing something or is this an obvious omission?

Comments

jhodgdon’s picture

Title: Documentation problem with hook_field_validate » hook_field_validate doc needs more information
Version: 7.x-dev » 8.x-dev
Issue tags: +Needs backport to D7

Thanks, good ideas on what to document...

chx’s picture

Status: Active » Closed (works as designed)
function field_default_form_errors($entity_type, $entity, $field, $instance, $langcode, $items, $form, &$form_state) {
          else {
            // Make sure that errors are reported (even incorrectly flagged) if
            // the widget module fails to implement hook_field_widget_error().
            form_error($error_element, $error['message']);
          }
}

From #369964: Refactor field validation and error reporting your only problem can be if your error is keyed wrong and you have FIELD_BEHAVIOR_CUSTOM defined.

jhodgdon’s picture

Version: 8.x-dev » 7.x-dev
Status: Closed (works as designed) » Active

We probably still need the documentation update for Drupal 7 though.

phryk’s picture

Yes please, this just cost me about an hour for D7 until I saw the comment. :<

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.