Projet

Général

Profil

Paste
Télécharger (2,2 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / modules / node / views_handler_field_node_revision.inc @ 13755f8d

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of views_handler_field_node_revision.
6
 */
7

    
8
/**
9
 * Contains the basic 'node_revision' field handler.
10
 */
11

    
12
/**
13
 * A basic node_revision handler.
14
 *
15
 * @ingroup views_field_handlers
16
 */
17
class views_handler_field_node_revision extends views_handler_field_node {
18
  function init(&$view, &$options) {
19
    parent::init($view, $options);
20
    if (!empty($this->options['link_to_node_revision'])) {
21
      $this->additional_fields['vid'] = 'vid';
22
      $this->additional_fields['nid'] = 'nid';
23
      if (module_exists('translation')) {
24
        $this->additional_fields['language'] = array('table' => 'node', 'field' => 'language');
25
      }
26
    }
27
  }
28
  function option_definition() {
29
    $options = parent::option_definition();
30
    $options['link_to_node_revision'] = array('default' => FALSE, 'bool' => TRUE);
31
    return $options;
32
  }
33

    
34
  /**
35
   * Provide link to revision option.
36
   */
37
  function options_form(&$form, &$form_state) {
38
    $form['link_to_node_revision'] = array(
39
      '#title' => t('Link this field to its content revision'),
40
      '#description' => t('This will override any other link you have set.'),
41
      '#type' => 'checkbox',
42
      '#default_value' => !empty($this->options['link_to_node_revision']),
43
    );
44
    parent::options_form($form, $form_state);
45
  }
46

    
47
  /**
48
   * Render whatever the data is as a link to the node.
49
   *
50
   * Data should be made XSS safe prior to calling this function.
51
   */
52
  function render_link($data, $values) {
53
    if (!empty($this->options['link_to_node_revision']) && $data !== NULL && $data !== '') {
54
      $this->options['alter']['make_link'] = TRUE;
55
      $nid = $this->get_value($values, 'nid');
56
      $vid = $this->get_value($values, 'vid');
57
      $this->options['alter']['path'] = 'node/' . $nid;
58
      if ($nid != $vid) {
59
        $this->options['alter']['path'] .= "/revisions/$vid/view";
60
      }
61
      if (module_exists('translation')) {
62
        $language = $this->get_value($values, 'language');
63
        $languages = language_list();
64
        if (isset($languages[$language])) {
65
          $this->options['alter']['language'] = $languages[$language];
66
        }
67
      }
68
    }
69
    else {
70
      return parent::render_link($data, $values);
71
    }
72
    return $data;
73
  }
74
}