hook_field_attach_validate

function hook_field_attach_validate

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: The array of errors (keyed by field name, language code, and delta) that have already been reported for the entity. The function should add its errors to this array. Each error is an associative array with the following keys and values:

  • error: An error code (should be a string prefixed with the module name).
  • message: The human readable message to be displayed.

Related topics

File

modules/field/field.api.php, line 1338
Hooks provided by the Field module.

Code

function hook_field_attach_validate($entity_type, $entity, &$errors) {
  // Make sure any images in article nodes have an alt text.
  if ($entity_type == 'node' && $entity->type == 'article' && !empty($entity->field_image)) {
    foreach ($entity->field_image as $langcode => $items) {
      foreach ($items as $delta => $item) {
        if (!empty($item['fid']) && empty($item['alt'])) {
          $errors['field_image'][$langcode][$delta][] = array(
            'error' => 'field_example_invalid',
            'message' => t('All images in articles need to have an alternative text set.'),
          );
        }
      }
    }
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!field!field.api.php/function/hook_field_attach_validate/7.x

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部