2

I am trying to load a node using the revisioning module to display an unpublished piece of content, by passing a version ID to node_load(). We also use the i18n module which may or may not have an affect on what I am trying to achieve. We are looking to implement a "preview" of a page which may be sent out to departments that do not have a user account of any sort (We do not want to create a login for this). The preview page is requested with the version &vid=12345 and a &preview URL parameter.

At the moment, if the specific revision is not published, the preview page will load the currently published content instead of the version we are passing to node_load().

I have tried to create a preview user with view unpublished permissions, but this does not work (still loads the published content).

Is it possible to prevent the fallback and load the specific revision?

UPDATE: Thank you for the renewed interest. So we are using the "entity_translation module" and have extended this to include the preview functionality. This allows a page URL to be called with the node id and version id. These are both passed to node_load. The node is then displayed via calls to $output = _revisioning_view($node); and finally drupal_deliver_page($output);

4
  • I think you'll need to provide some more information about how your preview page works to answer the problem. There's nothing in the node_load() or its function dependencies that restrict loading by the user role. Without clarity on how this preview page works, you can't get to the core of what you're asking.
    – Shawn Conn
    Nov 3, 2016 at 4:31
  • It would help if you could share a bit more of your code. Particularly whatever menu item you are using (or altering) to create this preview function. Likely you'll need to come up with a custom route and permissions to by-pass the security system since Drupal's default behavior will be to prevent this behaviors just like this (since it opens unpublished content to non-authenticated users).
    – acrosman
    Nov 6, 2016 at 20:09
  • Are you by any chance using workbench moderation module?
    – googletorp
    Nov 7, 2016 at 10:12
  • I've added more notes. @googletorp no, we're not using the workbench moderation module. Nov 10, 2016 at 15:22

1 Answer 1

3
+50

If you are doing this by custom method try below code to get published revision id.

$query = db_select('node_revision','nr');
$query->join('node','n','n.nid=nr.nid');
$query->fields('nr',array('vid','status','nid'));
$query->condition('nr.status',1,'=');
$query->condition('nr.nid',$nid,'=');
$result = $query->orderby('vid','DESC')->range(0,1)->execute()->fetchAll();

Pass $nid in condition, here you will get the latest published revision ID.

Then load node as

entity_revision_load('node', $result->vid)

This will load particular revision id with content type.

Here you will get all node data related to that revision id.

Hope this helps.

3
  • The node already loads correctly with node_load(node_id, version_id). The last call that our preview template makes is to drupal_deliver_page($output) where $output is created via a call to _revisioning_view($node). Nov 10, 2016 at 16:52
  • Is it possibe to change your output call to node_load(node_id, version_id) or with the above answer?
    – Ajay Reddy
    Nov 11, 2016 at 7:53
  • So change $output = _revisioning_view($node) to $output = entity_revision_load('node', $result->vid). It still loads the node, but the wrong revision. I am thinking that something after drupal_deliver_page is rolling back to the published revision rather than the one I am after. Nov 11, 2016 at 9:18

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.