You are here

function fape_field_edit_field_form_validate in Field API Pane Editor (FAPE) 7

Validate field editing form

1 string reference to 'fape_field_edit_field_form_validate'
fape_field_edit_field_form in ./fape.module
Subform to edit a field instance.

File

./fape.module, line 241
Adds direct field editing via contextual links.

Code

function fape_field_edit_field_form_validate($form, &$form_state) {
  ctools_include('fields');
  $entity_type = $form_state['entity_type'];
  $entity = $form_state['entity'];
  $field_name = $form_state['field_name'];
  $field_instance = $form_state['field_instance'];
  $langcode = $form_state['langcode'];

  // Extract field values from submitted values.
  ctools_field_invoke_field_default($field_instance, 'extract_form_values', $entity_type, $entity, $form, $form_state);
  $errors = array();

  // Check generic, field-type-agnostic errors first.
  ctools_field_invoke_field_default($field_instance, 'validate', $entity_type, $entity, $errors);

  // Check field-type specific errors.
  ctools_field_invoke_field($field_instance, 'validate', $entity_type, $entity, $errors);

  // Let other modules validate the entity.
  // Avoid module_invoke_all() to let $errors be taken by reference.
  foreach (module_implements('field_attach_validate') as $module) {
    $function = $module . '_field_attach_validate';
    $function($entity_type, $entity, $errors);
  }
  if ($errors) {

    // Pass field-level validation errors back to widgets for accurate error
    // flagging.
    foreach ($errors as $field_errors) {
      foreach ($field_errors as $langcode => $errors) {
        $field_state = field_form_get_state($form['#parents'], $field_name, $langcode, $form_state);
        $field_state['errors'] = $errors;
        field_form_set_state($form['#parents'], $field_name, $langcode, $form_state, $field_state);
      }
    }
    ctools_field_invoke_field_default($field_instance, 'form_errors', $entity_type, $entity, $form, $form_state);
  }
}