You are here

function heartbeat_comments_modal_delete in Heartbeat 7

Menu callback to delete a (node) comment in a ctools modal window.

1 string reference to 'heartbeat_comments_modal_delete'
heartbeat_comments_menu in modules/heartbeat_comments/heartbeat_comments.module
Implements hook_menu().

File

modules/heartbeat_comments/heartbeat_comments.module, line 932
Heartbeat comments for activity.

Code

function heartbeat_comments_modal_delete($js = NULL, $id) {
  $is_node = arg(6) == 'node' ? TRUE : FALSE;
  $uaid = arg(5);
  ctools_include('modal');
  if ($js) {
    ctools_include('ajax');
  }
  $form_state = array(
    'title' => t('Are you sure you want to delete this comment?'),
    'ajax' => TRUE,
    'id' => $id,
    'is_node' => $is_node,
  );

  // Send this all off to our form. This is like drupal_get_form only wizardy.
  $output = ctools_modal_form_wrapper('heartbeat_comments_delete_confirm', $form_state);

  // Fall back if $js is not set.
  if (!$js) {
    return drupal_get_form('heartbeat_comments_delete_confirm', $id, $form_state);
  }
  else {
    if (!empty($form_state['executed'])) {

      // We'll just overwrite the form output if it was successful.
      $output = array();
      $output[] = ctools_modal_command_dismiss();
      $output[] = ajax_command_invoke('#heartbeat-comment-' . $id, 'heartbeatRemoveElement', array(
        $id,
        t('Comment deleted.'),
      ));
    }
    print ajax_render($output);
    exit;
  }
}