[Drupal] How to change redirect path after node delete?

Data dodania wpisu: 15-11-2010

By default, after node delete in Drupal CMS we are redirectem onto the content list page. However, if we develop custom modules with custom content lists or tables (ie. Drupal-based online store, where we shall have custom products list table), we shall get custom redirection path. There are two common possibilities to do this in a right way. We can use 'destination' param in custom node delete url by this way:

$destination = 'destination=custom_page_url';
print l('Delete', 'node/' . $node->nid . '/delete', array('query' => $destination));

After node delete action Drupal will redirect onto 'custom_page_url' thankfully to 'destination' param in url query.

Another way is to create custom hook on Drupal node delete form by hook_form_alter() function:

function custom_module_form_alter($form, &$form_state, $form_id) {
    switch($form_id) {
        case 'node_delete_confirm':
            $form['#submit'][] = '_custom_redirect_after_delete';
    return $form;

function _custom_redirect_after_delete($form, &$form_state) {
    $form_state['redirect'] = 'custom_page_url';

After the node delete form is send, Drupal will redirect onto 'custom_page_url' added into the form_state params by custom function. Second method is available by developing simple custom module (http://drupal.org/node/206753).


You can use the Triggers in you drupal core

@Chintan: sure, my mistake, \"destination\" variable name must have gone somewhere;)
Fixed now, thx!
Solution One :
'query' => "destination=custom_page_url" worked for me not $destination varaible

l(t('Delete'),'node/'.$row->nid.'/delete',array('query' => "destination=custom_page_url"))
Thanks , It was exaclty what i was looking for
Comments closed...

DesignEnd on Facebook