1

I've edited the content type Book to "create a new revision" whenever user publishes the page (while creation and editing the page). snap

I have created a custom menu Book revisions, with path node/[node:nid]/revisions using menu token module. It renders http://site-url/4/revisions with 4 as the node id of current node.
I am using Nice menus module to create the menu block and have placed it on every book page so that user can see the revisions whenever he is on the book page.

When I first create a page, and click on this menu, it gives me Access denied page (I'm logged in as user1). But, the moment I edit the page and save it, it works as expected - showing the different revisions.
Requirement: I want to display "No revisions" instead of "Access denied" to users. How can this be done?
I'm also open to suggestions to hide the menu for the first time, and again show it as soon as a revision of the node is created.

Edit: I find that if a node is not revised (edited), node_revision table has only one vid for the nid of node; and if the node is revised the table contain one vid per revision.
Using this information and a database query, I think it would be possible to find out whether a node has revision. Something like

$result = db_query('SELECT n.nid from {node_revision} n WHERE n.nid LIKE :uid',array(':uid' => arg(1)));    
$temp_var = 0;
foreach ($result as $result_item) {
  $temp_var++;
}
//If revisions are present $temp_var>1
//Only one version present if $temp_var == 1
if($temp_var == 1) {
  //menu unset code goes here...
}

I am just not sure in which hook should I implement this.

EDIT: I'm using Diff module to enable the users to view the differences in two revisions.

  • Could you use a view to generate the "menu"? If you're using panels, you can sniff out revision status to determine whether or not to show the menu. – Jason Smith Jul 25 '12 at 15:40
  • I'm using nice menus module to generate the menu. Please see the edit. – AjitS Jul 27 '12 at 6:34
  • A shorter check for revision function has_revisions($nid) { $result = db_query("SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid", array(':nid' => $nid)); return ($result->fetchField() > 1); } Define a custom menu callback that accepts a nid. Redirect or api.drupal.org/api/drupal/includes%21common.inc/function/… – Jason Smith Jul 30 '12 at 14:14
2
+50

If I understood this right, you have a (Nice) menu on node pages, and you've added the node/[node:nid]/revisions item to that menu. You're not actually listing revisions, just making a link to the revisions page, right?

If so, the problem is that the access callback for that menu item is hardcoded to return access denied if a node doesn't have revisions. Actually looks like this is being fixed for D8. Normally the tab wouldn't show, but it is in your case because you're creating the menu item in a different way, and the access is not checked when the link is printed. The solutions I can think of:

  1. Replace the page with a view listing node revisions. Easy, but I don't know if you can replicate all the core revisions page functionality.
  2. Create a wrapper menu item around the core revisions page using hook_menu(). Call it something else, like node/%node/revs. In the callback for that menu item, check if the node has revisions. If so, return the output of node_revision_overview($nid), the core function that generates that page. Otherwise, return 'No revisions'
  3. Use hook_menu_alter() to take the existing revisions menu item (node/%node/revisions) and move it to your menu. Take a look at the definition of the menu item in node.module line 2043. You'll need to change it to not be a LOCAL_TASK and then use the menu_name property to tell it to get into your custom menu. I'm pretty sure this can work.
  • 1+ for hook_menu_alter and the answer in general. – amateur barista Jul 31 '12 at 6:57
  • thank you for the response. I'm testing the solution. Views has filters for revisions, but I'm using Diff module to find the difference in the revisions. I'm not sure how if the functionality of the module could be accommodated into a view. – AjitS Jul 31 '12 at 13:42
0

You could use a module that contextually defines which error page is shown to the user. Basically, you could create a node with content indicating there are no revisions to the book you are viewing and display that 403 page instead of the default 403 page through contexts (probably defined by URL structure including [node:nid]/revisions).

Try Context Error or perhaps CustomError.

  • I'll look at both of the options in the morning, and will let you know. thank you.. – AjitS Jul 31 '12 at 13:48

protected by kiamlaluno Jul 31 '12 at 16:38

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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