2

Sometimes when nodes are unpublished, they are not meant to be taken live again.

Under those circumstances, I would like to return a 410 Gone status, instead of the default 403 Forbidden.

Implementing the 410 itself is a 1 line patch to Page manager, but I soon realize that there is no easy way to get the response to the client, as the router system itself checks the node status, and denies access.

How can I force the menu router to process my request for an unpublished node as usual?

2 Answers 2

3

I haven't tried this myself, but I think the main problem is that in your cases, the "unpublished status" means two things.

I think your best bet is to use something like Workbench Moderation, and defined a "retired" state. Then, in a hoot_init(), check the status, and generate the 410.

Something like:

function mymodule_init ()
{
   $node = menu_get_object();
   if (isset($node->nid) && this_is_a_retired_node($node)) {
     drupal_add_http_header('Status', '410 Gone');
     drupal_exit(); // may want exit instead; not sure of other hook_inits()s should run
   }
}

I think you have to take the sledgehammer approach so that you don't get too far into the request where you may have a race condition with other modules.

1
  • I'm actually looking at hook_init right now, but I haven't figured out how I would set the status code.
    – Letharion
    Aug 10, 2012 at 11:20
2

Ultimately, the current 403 is coming from node_access, hook_menu_alter'ing a wrapper around that function may be able to solve this problem.

1
  • 2
    That could potentially work. You would probably also want to wrap the "page callback" so that you can just output a simple message instead of a full Drupal page.
    – mpdonadio
    Aug 10, 2012 at 13:09

Your Answer

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

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