Projet

Général

Profil

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

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

1
<?php
2

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

    
8
/**
9
 * Field handler to allow linking to a user account or homepage.
10
 *
11
 * @ingroup views_field_handlers
12
 */
13
class views_handler_field_comment_username extends views_handler_field {
14

    
15
  /**
16
   * Override init function to add uid and homepage fields.
17
   */
18
  public function init(&$view, &$data) {
19
    parent::init($view, $data);
20
    $this->additional_fields['uid'] = 'uid';
21
    $this->additional_fields['homepage'] = 'homepage';
22
  }
23

    
24
  /**
25
   * {@inheritdoc}
26
   */
27
  public function option_definition() {
28
    $options = parent::option_definition();
29
    $options['link_to_user'] = array('default' => TRUE, 'bool' => TRUE);
30
    return $options;
31
  }
32

    
33
  /**
34
   * {@inheritdoc}
35
   */
36
  public function options_form(&$form, &$form_state) {
37
    $form['link_to_user'] = array(
38
      '#title' => t("Link this field to its user or an author's homepage"),
39
      '#type' => 'checkbox',
40
      '#default_value' => $this->options['link_to_user'],
41
    );
42
    parent::options_form($form, $form_state);
43
  }
44

    
45
  /**
46
   * {@inheritdoc}
47
   */
48
  public function render_link($data, $values) {
49
    if (!empty($this->options['link_to_user'])) {
50
      $account = new stdClass();
51
      $account->uid = $this->get_value($values, 'uid');
52
      $account->name = $this->get_value($values);
53
      $account->homepage = $this->get_value($values, 'homepage');
54

    
55
      return theme('username', array(
56
        'account' => $account
57
      ));
58
    }
59
    else {
60
      return $data;
61
    }
62
  }
63

    
64
  /**
65
   * {@inheritdoc}
66
   */
67
  public function render($values) {
68
    $value = $this->get_value($values);
69
    return $this->render_link($this->sanitize_value($value), $values);
70
  }
71

    
72
}