summaryrefslogtreecommitdiff
path: root/modules/field
diff options
context:
space:
mode:
authorJennifer Hodgdon <yahgrp@poplarware.com>2014-10-19 06:09:58 -0700
committerJennifer Hodgdon <yahgrp@poplarware.com>2014-10-19 06:09:58 -0700
commit57236b056f8785137d27f6f5ba99a40127dc1c51 (patch)
tree5350b667f5bfa8ed250b33fac0d858baf70f94b1 /modules/field
parentb4844afdcadbaa7e4f3ad9a237f17126b94dc483 (diff)
downloadbrdo-57236b056f8785137d27f6f5ba99a40127dc1c51.tar.gz
brdo-57236b056f8785137d27f6f5ba99a40127dc1c51.tar.bz2
Issue #2329189 by nlisgo, joachim, Mirroar, opdavies: Fix up docs and example code for hook_field_attach_validate()
Diffstat (limited to 'modules/field')
-rw-r--r--modules/field/field.api.php21
1 files changed, 19 insertions, 2 deletions
diff --git a/modules/field/field.api.php b/modules/field/field.api.php
index 365fc404c..e8361c22e 100644
--- a/modules/field/field.api.php
+++ b/modules/field/field.api.php
@@ -1328,10 +1328,27 @@ function hook_field_attach_load($entity_type, $entities, $age, $options) {
* @param $entity
* The entity with fields to validate.
* @param array $errors
- * An associative array of errors keyed by field_name, language, delta.
+ * 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.
*/
function hook_field_attach_validate($entity_type, $entity, &$errors) {
- // @todo Needs function body.
+ // 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.'),
+ );
+ }
+ }
+ }
+ }
}
/**