3

I am using the Revisioning module to handle content revisions and I am creating a custom block that needs the vid of the node that the user is viewing to generate the appropriate content. I was trying to use menu_get_object() to obtain this and it works fine for a node with no revisions.

When I have a pending revision in Draft that I am looking at via the "View latest" tab, the node->vid I obtain from menu_get_object() is the vid of the "current" version, not the "latest". What would be the best way for me to obtain the vid of the version that is actually being displayed to the user?

1

2 Answers 2

3

I dug into the Revisioning module to see how they are doing the check and adapted it for use in a helper function in my module. I first load the node using menu_get_object() and then call the following:

function _get_correct_revision($node) {
  if (module_exists('revisioning')) {
    if (_revisioning_load_op($node, 'view') == REVISIONING_LOAD_LATEST) {
      $vid_to_load = revisioning_get_latest_revision_id($node->nid);
      $node = node_load($node->nid, $vid_to_load);
    }
  }
  return $node->vid;
}
1
1

The project page for revisioning says that node_load will offer some extra attributes related to revisions and I think you are looking for:

$node->is_pending;
2
  • I don't have the $node object available to me in the block hook. Commented Mar 20, 2011 at 15:36
  • As you wrote in your own answer, you can get the node object of the current page with menu_get_object().
    – Berdir
    Commented Apr 4, 2011 at 14:20

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.