~spreadubuntu/spreadubuntu/devel-drupal6

« back to all changes in this revision

Viewing changes to modules/views/modules/node/views_handler_field_node_revision_link_revert.inc

  • Committer: ruben
  • Date: 2009-06-08 09:38:49 UTC
  • Revision ID: ruben@captive-20090608093849-s1qtsyctv2vwp1x1
SpreadUbuntu moving to Drupal6. Based on ubuntu-drupal theme and adding our modules

Show diffs side-by-side

added added

removed removed

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