0

How to Delete nodes for specific Content type without redirect to a confirm delete page ?

function _node_delete_function($node) {
  if ($node->type == 'bills') {
    node_delete($node->nid);
    drupal_goto();
 }    
  else {
   
   return drupal_get_form('node_delete_confirm', $node);
  }
}

Any help?

1 Answer 1

0

You can use hook_menu_alter().

Example :

/**
 * Implements hook_menu_alter().
 */
function Module_menu_alter(&$items) {
  $items['node/%node/delete']['page arguments'] = array('_custom_node_delete', 1);
}

/*
 * Custom delete.
 */
function _custom_node_delete($form, &$form_state, $node) {
  node_delete($node->nid);
  cache_clear_all();
  watchdog('content', '@type: deleted %title.', array('@type' => $node->type, '%title' => $node->title));
  drupal_set_message(
    t('@type %title has been deleted.', array('@type' => node_type_get_name($node), '%title' => $node->title))
  );
  $form_state['redirect'] = '<front>';
}
2
  • I can't save any new node with the code !!
    – Barry
    May 16, 2017 at 15:13
  • I dont understand why you want save a new node. May 17, 2017 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.