You are here

function ajax_form_entity_entity_delete_callback in Ajax form entity 7

Same name and namespace in other branches
  1. 7.x ajax_form_entity.callback.inc \ajax_form_entity_entity_delete_callback()

Ajax callback for deletion (ajax delete link).

1 string reference to 'ajax_form_entity_entity_delete_callback'
ajax_form_entity_menu in ./ajax_form_entity.module
Implements hook_menu().

File

./ajax_form_entity.callback.inc, line 44

Code

function ajax_form_entity_entity_delete_callback($type = 'ajax') {
  $entity_type = arg(3);
  $entity_id = arg(4);
  $special_id = arg(5);

  // Load entity to check access.
  $ids[] = $entity_id;
  $entity = entity_load($entity_type, $ids);
  if (entity_access('delete', $entity_type, $entity[$entity_id]) && isset($_SESSION['ajax_form_entity_delete'][$special_id])) {
    if ($type == 'ajax') {

      //$message = t('Deleted');
      $vars['content'] = 'Deleted';
      $message = theme('ajax_form_entity_deleted', $vars);

      //  For field collection, apply the delete class of Field collection to delete references from host entity.
      if ($entity_type == 'field_collection_item') {
        $entity[$entity_id]
          ->delete();
      }
      else {
        entity_delete($entity_type, $entity_id);
      }
      $commands[] = ajax_command_replace('#ajax-entity-form-' . $special_id, $message . theme('status_messages'));
      $page = array(
        '#type' => 'ajax',
        '#commands' => $commands,
      );
      ajax_deliver($page);
    }
    else {

      // TODO : no javascript.
    }
  }
}