You are here

function slickgrid_editor_form_validate in Slickgrid 7

Same name and namespace in other branches
  1. 7.2 slickgrid.module \slickgrid_editor_form_validate()

Validate the slickgrid editor form If multiple items are being edited, need to ensure all are validated properly

_state

Parameters

unknown_type $form:

File

./slickgrid.module, line 585

Code

function slickgrid_editor_form_validate($form, &$form_state) {
  $editor =& $form_state['editor'];

  // Loop through all of the entities
  foreach ($editor->entities as $entity) {
    list($id, $vid, $bundle_name) = entity_extract_ids($editor->entity_type, $entity);
    if ($instance = field_info_instance($editor->entity_type, $editor->field_id, $bundle_name)) {
      _field_invoke_default('extract_form_values', $editor->entity_type, $entity, $form, $form_state);
      try {
        field_attach_validate($editor->entity_type, $entity);

        // If reached here, validation has passed
        continue;
      } catch (FieldValidationException $e) {
        foreach ($e->errors as $field_name => $field_errors) {
          $error .= $field_errors;
        }
      }
    }
    else {
      $error = t('Field doesn\'t exist');
    }

    // If got to this point the bundle failed validation
    $editor
      ->set_error($id, $error);

    // Set form error to prevent form submission
    form_set_error($editor->field_id, t('Validation error'));
  }
}