Projet

Général

Profil

Révision b4adf10d

Ajouté par Assos Assos il y a plus de 9 ans

Udpate to 7.33

Voir les différences:

drupal7/modules/field/field.api.php
1328 1328
 * @param $entity
1329 1329
 *   The entity with fields to validate.
1330 1330
 * @param array $errors
1331
 *   An associative array of errors keyed by field_name, language, delta.
1331
 *   The array of errors (keyed by field name, language code, and delta) that
1332
 *   have already been reported for the entity. The function should add its
1333
 *   errors to this array. Each error is an associative array with the following
1334
 *   keys and values:
1335
 *   - error: An error code (should be a string prefixed with the module name).
1336
 *   - message: The human readable message to be displayed.
1332 1337
 */
1333 1338
function hook_field_attach_validate($entity_type, $entity, &$errors) {
1334
  // @todo Needs function body.
1339
  // Make sure any images in article nodes have an alt text.
1340
  if ($entity_type == 'node' && $entity->type == 'article' && !empty($entity->field_image)) {
1341
    foreach ($entity->field_image as $langcode => $items) {
1342
      foreach ($items as $delta => $item) {
1343
        if (!empty($item['fid']) && empty($item['alt'])) {
1344
          $errors['field_image'][$langcode][$delta][] = array(
1345
            'error' => 'field_example_invalid',
1346
            'message' => t('All images in articles need to have an alternative text set.'),
1347
          );
1348
        }
1349
      }
1350
    }
1351
  }
1335 1352
}
1336 1353

  
1337 1354
/**

Formats disponibles : Unified diff