Projet

Général

Profil

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

root / drupal7 / sites / all / modules / views / modules / comment / views_handler_field_comment_link.inc @ 5d12d676

1
<?php
2

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

    
8
/**
9
 * Base field handler to present a link.
10
 *
11
 * @ingroup views_field_handlers
12
 */
13
class views_handler_field_comment_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
    $options['link_to_node'] = array('default' => FALSE, 'bool' => TRUE);
22
    return $options;
23
  }
24

    
25
  /**
26
   * {@inheritdoc}
27
   */
28
  public function options_form(&$form, &$form_state) {
29
    $form['text'] = array(
30
      '#type' => 'textfield',
31
      '#title' => t('Text to display'),
32
      '#default_value' => $this->options['text'],
33
    );
34
    $form['link_to_node'] = array(
35
      '#title' => t('Link field to the node if there is no comment.'),
36
      '#type' => 'checkbox',
37
      '#default_value' => $this->options['link_to_node'],
38
    );
39
    parent::options_form($form, $form_state);
40
  }
41

    
42
  /**
43
   * {@inheritdoc}
44
   */
45
  public function query() {
46
    $this->ensure_my_table();
47
    $this->add_additional_fields();
48
  }
49

    
50
  /**
51
   * {@inheritdoc}
52
   */
53
  public function render($values) {
54
    $value = $this->get_value($values, 'cid');
55
    return $this->render_link($this->sanitize_value($value), $values);
56
  }
57

    
58
  /**
59
   * {@inheritdoc}
60
   */
61
  public function render_link($data, $values) {
62
    $text = !empty($this->options['text']) ? $this->options['text'] : t('view');
63
    $comment = $this->get_value($values);
64
    $nid = $comment->nid;
65
    $cid = $comment->cid;
66

    
67
    $this->options['alter']['make_link'] = TRUE;
68
    $this->options['alter']['html'] = TRUE;
69

    
70
    if (!empty($cid)) {
71
      $this->options['alter']['path'] = "comment/" . $cid;
72
      $this->options['alter']['fragment'] = "comment-" . $cid;
73
    }
74
    // If there is no comment link to the node.
75
    elseif ($this->options['link_to_node']) {
76
      $this->options['alter']['path'] = "node/" . $nid;
77
    }
78

    
79
    return $text;
80
  }
81

    
82
}