views_handler_field_node_revision_link.inc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_field_node_revision_link.
  5. */
  6. /**
  7. * Field handler to present a link to a node revision.
  8. *
  9. * @ingroup views_field_handlers
  10. */
  11. class views_handler_field_node_revision_link extends views_handler_field_node_link {
  12. function construct() {
  13. parent::construct();
  14. $this->additional_fields['node_vid'] = array('table' => 'node_revision', 'field' => 'vid');
  15. }
  16. function access() {
  17. return user_access('view revisions') || user_access('administer nodes');
  18. }
  19. function render_link($data, $values) {
  20. list($node, $vid) = $this->get_revision_entity($values, 'view');
  21. if (!isset($vid)) {
  22. return;
  23. }
  24. // Current revision uses the node view path.
  25. $path = 'node/' . $node->nid;
  26. if ($node->vid != $vid) {
  27. $path .= "/revisions/$vid/view";
  28. }
  29. $this->options['alter']['make_link'] = TRUE;
  30. $this->options['alter']['path'] = $path;
  31. $this->options['alter']['query'] = drupal_get_destination();
  32. return !empty($this->options['text']) ? $this->options['text'] : t('view');
  33. }
  34. /**
  35. * Returns the revision values of a node.
  36. *
  37. * @param object $values
  38. * An object containing all retrieved values.
  39. * @param string $op
  40. * The operation being performed.
  41. *
  42. * @return array
  43. * A numerically indexed array containing the current node object and the
  44. * revision ID for this row.
  45. */
  46. function get_revision_entity($values, $op) {
  47. $vid = $this->get_value($values, 'node_vid');
  48. $node = $this->get_value($values);
  49. // Unpublished nodes ignore access control.
  50. $node->status = 1;
  51. // Ensure user has access to perform the operation on this node.
  52. if (!node_access($op, $node)) {
  53. return array($node, NULL);
  54. }
  55. return array($node, $vid);
  56. }
  57. }