1 image.field.inc _image_field_widget_alt_validate($element, &$form_state)

Validate callback for alt field.

This is separated in a validate function instead of a #required flag to avoid being validated on the process callback.

File

core/modules/image/image.field.inc, line 598
Implement an image field, based on the file module's file field.

Code

function _image_field_widget_alt_validate($element, &$form_state) {
  // Only do validation if the function is triggered from other places than
  // the image process form.
  if (isset($form_state['triggering_element']['#submit']) && !in_array('file_managed_file_submit', $form_state['triggering_element']['#submit'])) {
    // If the image is not there, we do not check for empty values.
    $parents = $element['#parents'];
    $field = array_pop($parents);
    $image_field = backdrop_array_get_nested_value($form_state['input'], $parents);
    if ($image_field == NULL) {
      $image_field = array();
    }
    // We check for the array key, so that it can be NULL (like if the user
    // submits the form without using the "upload" button).
    if (!array_key_exists($field, $image_field)) {
      return;
    }
    // Check if the field is left empty.
    elseif (empty($image_field[$field])) {
      form_error($element, t('The %title field is required.', array('%title' => $element['#title'])));
      return;
    }
  }
}