You are here

function slickgrid_editor_form_submit in Slickgrid 7

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

File

./slickgrid.module, line 612

Code

function slickgrid_editor_form_submit($form, &$form_state) {
  $editor =& $form_state['editor'];
  foreach ($editor->entities as $entity) {

    // Get the entity ids
    list($id, $vid, $bundle_name) = entity_extract_ids($editor->entity_type, $entity);

    // Create an instance of the field
    if (!($instance = field_info_instance($editor->entity_type, $editor->field_id, $bundle_name))) {

      // Add entity to the editor's error array
      $editor
        ->set_error($id, t('Field does not exist for this bundle'), 'submit');
      continue;
    }

    // Populate the entity with the submitted values
    entity_form_submit_build_entity($editor->entity_type, $entity, $form, $form_state);

    // Try to save the entity
    try {
      entity_save($editor->entity_type, $entity);

      // Add entity to the editor's updated array
      $editor->updated[$id] = array(
        'vid' => $vid,
      );
    } catch (Exception $e) {

      // Add entity to the editor's error array
      $editor
        ->set_error($id, t('Error trying to update entity'), 'submit');
    }
  }
}