function hook_field_attach_validate

You are here

7 field.api.php hook_field_attach_validate($entity_type, $entity, &$errors)

Act on field_attach_validate().

This hook is invoked after the field module has performed the operation.

See field_attach_validate() for details and arguments.

Parameters

$entity_type: The type of $entity; e.g., 'node' or 'user'.

$entity: The entity with fields to validate.

array $errors: An associative array of errors keyed by field_name, language, delta.

Related topics

1 invocation of hook_field_attach_validate()
field_attach_validate in modules/field/field.attach.inc
Perform field validation against the field data in an entity.

File

modules/field/field.api.php, line 1323

Code

function hook_field_attach_validate($entity_type, $entity, &$errors) {
  // @todo Needs function body.
}

Comments

FieldValidationException If validation errors are found, a FieldValidationException is thrown. The 'errors' property contains the array of errors, keyed by field name, language and delta.

Use it as in the example :

        $errors[$field_name]][$langcode][$delta][] = array(
          'error' => 'field_example_invalid',
          'message' => t('Color must be in the HTML format #abcdef.'),
        );

Beware of the typo in the first line (superfluous square bracket).

The correct code is:

<?php
  $errors
[$field_name][$langcode][$delta][] = array(
   
'error' => 'field_example_invalid',
   
'message' => t('Color must be in the HTML format #abcdef.'),
  );
?>