Error from hook_field_validate() isn't detected by hook_field_widget_error()

Just like the title says, for some reason my hook_field_widget_error() isn't getting fired.

Here's my code:


function guideform_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, $errors) {   foreach ($items as $delta => $item) {     foreach (array('fullItems', 'startItems') as $column) {       if (!empty($item[$column])) {         $fieldName = $instance['field_name'];         switch ($column) {           case 'fullItems':             if (drupal_strlen($item[$column]) > 200) {               $message = t("The field {$fieldID} is too big");             }             break;           case 'startItems':             if (drupal_strlen($item[$column]) > 100) {               $message = t("The field {$fieldID} is too big");             }             break;         }         if (isset($message)) {                     $errors[$field['field_name']][$langcode][$delta][] = array(              'error' => "field_max_length",             'message' => $message,           );           //dpm just for checking, prints correctly           dpm($errors); //appears with the same format of other implementations of this hook         }       }     }   } } 


function guideform_field_widget_error($element, $error, $form, &$form_state) {    dpm($error); //this doesn't print, hook is not fired   switch ($error['error']) {     case 'field_max_length':       form_error($element, $error['message']);       break;   } } 

Just for comparison, these are the same hooks implemented in the examples module by the field example:


function field_example_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {   foreach ($items as $delta => $item) {     if (!empty($item['rgb'])) {       if (!preg_match('@^#[0-9a-f]{6}[email protected]', $item['rgb'])) {         $errors[$field['field_name']][$langcode][$delta][] = array(           'error' => 'field_example_invalid',           'message' => t('Color must be in the HTML format #abcdef.'),         );       }     }   } } 


function field_example_field_widget_error($element, $error, $form, &$form_state) {   switch ($error['error']) {     case 'field_example_invalid':       form_error($element, $error['message']);       break;   } } 

These do work as intended. Is there anything else I should look for aside from those 2 hooks in order to be able to flag those field errors?


Category: 7 Time: 2016-07-31 Views: 2
Tags: forms fields

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.137 (s). 12 q(s)