function slickgrid_editor_form_validate in Slickgrid 7.2
Same name and namespace in other branches
- 7 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 607
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);
// Check access
if ($editor->entity_type == 'file' && !file_entity_access('update') || $editor->entity_type != 'file' && !entity_access('update', $editor->entity_type, $entity)) {
// User doesn't have access to edit
$error = t('You do not have access to update this @type', array(
'@type' => isset($entity->type) ? $entity->type : $editor->entity_type,
));
}
elseif ($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 .= strip_tags(_slickgrid_editor_get_form_error_message($field_errors));
}
}
}
elseif (!isset($form['#entity_property'])) {
$error = t('Field doesn\'t exist');
}
if (isset($error)) {
// 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'));
}
}
}