Projet

Général

Profil

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

root / drupal7 / sites / all / modules / views / modules / comment / views_handler_field_comment_link.inc @ 7547bb19

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
  function construct() {
15
    parent::construct();
16
  }
17

    
18
  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
  function options_form(&$form, &$form_state) {
26
    $form['text'] = array(
27
      '#type' => 'textfield',
28
      '#title' => t('Text to display'),
29
      '#default_value' => $this->options['text'],
30
    );
31
    $form['link_to_node'] = array(
32
      '#title' => t('Link field to the node if there is no comment.'),
33
      '#type' => 'checkbox',
34
      '#default_value' => $this->options['link_to_node'],
35
    );
36
    parent::options_form($form, $form_state);
37
  }
38

    
39
  function query() {
40
    $this->ensure_my_table();
41
    $this->add_additional_fields();
42
  }
43

    
44
  function render($values) {
45
    $value = $this->get_value($values, 'cid');
46
    return $this->render_link($this->sanitize_value($value), $values);
47
  }
48

    
49
  function render_link($data, $values) {
50
    $text = !empty($this->options['text']) ? $this->options['text'] : t('view');
51
    $comment = $this->get_value($values);
52
    $nid = $comment->nid;
53
    $cid = $comment->cid;
54

    
55
    $this->options['alter']['make_link'] = TRUE;
56
    $this->options['alter']['html'] = TRUE;
57

    
58
    if (!empty($cid)) {
59
      $this->options['alter']['path'] = "comment/" . $cid;
60
      $this->options['alter']['fragment'] = "comment-" . $cid;
61
    }
62
    // If there is no comment link to the node.
63
    else if ($this->options['link_to_node']) {
64
      $this->options['alter']['path'] = "node/" . $nid;
65
    }
66

    
67
    return $text;
68
  }
69
}