Hello everyone,

I'm trying to link to the newest/pending revision through Views and I can't seem to find out how.

For example say my nid = 123, my current published vid = 456, and my submitted pending review vid = 789 then how do I link to this page within my View Fields area?

http://www.example.com/node/123/revisions/789/view

I don't see the proper field to get the latest/pending revision vid. I'm looking for something along the lines of Node: Pending vid.

Thanks for reading.
-Tim

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MohamedAli’s picture

I'm searching for something similar to that, when you found something let me know...

Thanks

RdeBoer’s picture

Hi,
You don't have to do it through Views, you can use your normal link to the node as produced in the View, eg http://www.example.com/node/123. Then you configure what happens when people click on it (i.e. either load the current or latest revision) through Revisioning. You do this at Admin >>Site Configuration >> Revisioning.

The downside (or is it an upside?) is that clicking on any link that points to http://www.example.com/node/123 anywhere on your site will take you to the latest revision.

Alternatively in your view create links to the /revisions tab, eg http://www.example.com/node/123/revisions, from which they can then pick the revision they want.

If none of this what your are after and only want them to go this particular pending revision then this will require some extra Revisioning/Views code, I think.
Rik

giorgio79’s picture

+1

Perhaps with http://drupal.org/project/views_php? We would just need a snippet to get the latest revision for a node :)

Being able to have a link from a View straight to the latest revision saves some clicking, we can skip the revisions page.

giorgio79’s picture

Oh I think I even found the snippet :)

http://drupal.stackexchange.com/questions/1010/how-can-i-obtain-the-late...

No need for a custom module though, just a Views PHP field...

RdeBoer’s picture

Assigned: Unassigned » RdeBoer
Status: Active » Fixed

@giorgio:
Thanks for the link to http://drupal.stackexchange.com -- I didn't know this site, let alone that my module got mentioning!

Yep, the "Views PHP" module will work.
I would use a different code-snippet for the Global PHP field tough. This is what I just did. I tested this in D7, but D6 will be identical.

I installed and enabled Views PHP.
I then edited the existing "Content summary" View to add a "Global PHP" field.
In the "output code" section of the Global PHP form I entered the following:

<?php
  $nid = $row->nid;
  $vid = revisioning_get_latest_revision_id($nid);
  echo "<a href='node/$nid/revisions/$vid/edit'>Edit latest</a>"; 
?>

This will create a colum in your View that contains for each piece of conent listed a link to edit the latest revision of that content (will be the current revision if the content has no pending revisions). If you want a link to view (rather than edit) the latest revision, just change the word "edit" to "view" in the code snippet above.

giorgio79’s picture

Lovely, thanks Rik.

giorgio79’s picture

Just one question, lets say if there is no revision yet, the edit link should go to create new page, it would look like this right?

<?php
  $nid = $data->nid;
  $vid = revisioning_get_latest_revision_id($nid);
if ($data->vid == $vid)
echo
  echo "<a href='node/$nid/edit'>Edit</a>"; 
else
  echo "<a href='node/$nid/revisions/$vid/edit'>Edit latest</a>"; 
?>

PS: replace $nid with $node->vid, also $row did not contain the node object for me in views php only $data.

RdeBoer’s picture

Status: Closed (fixed) » Fixed

URLs of the form 'node/%/revisions/%/edit don't work for content that is not subject to moderation, at least not in D7. So for D7 (or for D6, if you want to have different link texts for the two cases) you'd use something like this:

<?php
  $nid = $row->nid; // $data->nid in D6 ?
  $latest_vid = revisioning_get_latest_revision_id($nid);
  $current_vid = revisioning_get_current_node_revision_id($nid);
  if ($current_vid == $latest_vid) {
    echo "<a href='node/$nid/edit'>Edit current</a>"; 
  } else {
    echo "<a href='node/$nid/revisions/$latest_vid/edit'>Edit pending</a>"; 
  }
?>

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

cecrs’s picture

Issue summary: View changes
Status: Closed (fixed) » Needs review
FileSize
2.5 KB

I had this same need, so I wrote a field handler to grab the latest vid, as I didn't particularly wish to use Views PHP. Patch is attached, against 6.x-3.x dev branch.

RdeBoer’s picture

Thanks for the patch, cecrs!
Rik

RdeBoer’s picture

Status: Needs review » Closed (won't fix)

Only doing bug fixes and patches for D6. Sorry.