By Dubber Dan on
By default Drupal redirects to the homepage when a node is deleted. How do I set things up so that the user is redirected to a specific node (node/add)?
By default Drupal redirects to the homepage when a node is deleted. How do I set things up so that the user is redirected to a specific node (node/add)?
Comments
This can be done in many
This can be done in many ways. The most easy one is to alter the confirmation form of a node delete. I have created a small module to demonstrate.
put this in delete_path.info
put this in delete_path.module
Note that this code doesn't work when deleting multiple nodes from 'admin/content/node'. This uses a different confirmation form. You can add this form in hook_form_alter. The same functionality could be achieved by hook_nodeapi () with the operator 'delete'. In all cases make sure that your module is the last to be executed (change the weight of the module in the table 'system').
Where do these go?
Thanks for that, but I'm wondering where these two files go?
I tried creating a delete_path directory in sites/default/modules with those two files inside, but then got an error message on the modules page.
What is the error? And try to
What is the error? And try to put it in 'sites/all/modules'.
That did the trick
Sticking it in 'sites/all/modules' sorted it and there's now no error and it works.
I have noticed something odd in how it works though. If the node is deleted by viewing the node, then clicking edit and then deleting it redirects to 'node/add'. However if I go to 'admin/content/node' then click on the edit link for that node and delete, it then comes back to that list of content.
So looking at your original message, it seems it's not just deleting multiple nodes at once from that list that behaves differently, but also editing/deleting a single node from that list.
So not a deal breaker, but something to be aware of. I'm not sure how I would code to cover that situation, so any pointers greatly welcomed.
Have you thought of releasing this as a proper module, as I'm sure others would find it useful too?
Dubber dan. I my first post I
Dubber dan.
I my first post I already described that multiple nodes wouldn't work because it uses a different confirmation form. This form_id can be added to the hook_form_alter to make it work.
I think not many people need such a module but maybe I'm wrong at this point. I already have the burden of maintaining two modules. Maybe there is someone else who wants to create a more general module for this purpose.
Not just multiple nodes
Yep, I commented about the multiple nodes. But what I was referring to was not selecting multiple nodes, but going in to edit one specific node from the complete content list, and then deleting that single node and what appears to be the normal fashion.
It seems that not only the content list page uses a different form, but accessing a single node from that list, then deleting uses a different form to editing and deleting a node direct rather than from the content list.
As it is, the way it redirects back to the content list seems to be the sensible place to go to as that is where the node was accessed from.
I'm looking for such a
I'm looking for such a solution.
However in my case, I don't grant administer content for 'Content Editor' role , so I created a page views, a table with fields, node title, node type,post date, delete link and edit link.
If a user click the edit link and click delete button from the node edit form, how drupal know the path redirect from and redirect back after deleting a node ?
Normally your delete link in
Normally your delete link in a view would point to something like http://example.com/node/123/delete?destination=path_of_the_view. So after clicking on the delete link in your view you would return to the same view. If you want to change the destionation then it is very easy to rewrite the output of your field 'delete link'. I have added a view code where you can see how I rewrote the delete link to point to node/123 after clicking on a delete link. Import this view to see it working. I Hope this helps:
Thank you!
Exactly what I was looking for. Thank you very much, peter-boeren.
I know, old thread
I know this is an old thread, but could you accomplish the same thing in template.php? Just seems like you could set up a hook form alter there... Just curious!
I haven't tried it but
I haven't tried it but template.php is normally not the place to place hook_form_alters. The hooks are fired from a function called module_invoke or module_invoke_all. (http://api.drupal.org/api/drupal/includes--module.inc/function/module_in...) As you can see it tries to find a function in a $module. Let me know why you would prefer template.php for this action?
For Drupal 7
In our case, if the node being deleted is a "tracker" type, we wanted to return to the "trackers" menu item.
NancyDru