Projet

Général

Profil

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

root / drupal7 / sites / all / modules / views / modules / node / views_handler_field_node_link.inc @ 5d12d676

1
<?php
2

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

    
8
/**
9
 * Field handler to present a link to the node.
10
 *
11
 * @ingroup views_field_handlers
12
 */
13
class views_handler_field_node_link extends views_handler_field_entity {
14

    
15
  /**
16
   * {@inheritdoc}
17
   */
18
  public function option_definition() {
19
    $options = parent::option_definition();
20
    $options['text'] = array('default' => '', 'translatable' => TRUE);
21
    return $options;
22
  }
23

    
24
  /**
25
   * {@inheritdoc}
26
   */
27
  public function options_form(&$form, &$form_state) {
28
    $form['text'] = array(
29
      '#type' => 'textfield',
30
      '#title' => t('Text to display'),
31
      '#default_value' => $this->options['text'],
32
    );
33
    parent::options_form($form, $form_state);
34

    
35
    // The path is set by render_link function so don't allow to set it.
36
    $form['alter']['path'] = array('#access' => FALSE);
37
    $form['alter']['external'] = array('#access' => FALSE);
38
  }
39

    
40
  /**
41
   * {@inheritdoc}
42
   */
43
  public function render($values) {
44
    if ($entity = $this->get_value($values)) {
45
      return $this->render_link($entity, $values);
46
    }
47
  }
48

    
49
  /**
50
   * {@inheritdoc}
51
   */
52
  public function render_link($node, $values) {
53
    if (node_access('view', $node)) {
54
      $this->options['alter']['make_link'] = TRUE;
55
      $this->options['alter']['path'] = "node/$node->nid";
56
      $text = !empty($this->options['text']) ? $this->options['text'] : t('view');
57
      return $text;
58
    }
59
  }
60

    
61
}