views_handler_field_node_revision_link_revert.inc

  1. 3.x modules/node/views_handler_field_node_revision_link_revert.inc
  2. 2.x modules/node/views_handler_field_node_revision_link_revert.inc

File

modules/node/views_handler_field_node_revision_link_revert.inc
View source
  1. <?php
  2. /**
  3. * Field handler to present a link to revert a node to a revision
  4. */
  5. class views_handler_field_node_revision_link_revert extends views_handler_field_node_link {
  6. function construct() {
  7. parent::construct();
  8. $this->additional_fields['uid'] = array('table' => 'node', 'field' => 'uid');
  9. $this->additional_fields['node_vid'] = array('table' => 'node', 'field' => 'vid');
  10. $this->additional_fields['vid'] = 'vid';
  11. $this->additional_fields['format'] = 'format';
  12. }
  13. function access() {
  14. return user_access('revert revisions') || user_access('administer nodes');
  15. }
  16. function render($values) {
  17. // ensure user has access to edit this node.
  18. $node = new stdClass();
  19. $node->nid = $values->{$this->aliases['nid']};
  20. $node->vid = $values->{$this->aliases['vid']};
  21. $node->uid = $values->{$this->aliases['uid']};
  22. $node->format = $values->{$this->aliases['format']};
  23. $node->status = 1; // unpublished nodes ignore access control
  24. if (!node_access('update', $node)) {
  25. return;
  26. }
  27. // Current revision cannot be reverted.
  28. if ($node->vid == $values->{$this->aliases['node_vid']}) {
  29. return;
  30. }
  31. $text = !empty($this->options['text']) ? $this->options['text'] : t('revert');
  32. return l($text, "node/$node->nid/revisions/$node->vid/revert", array('query' => drupal_get_destination()));
  33. }
  34. }