Projet

Général

Profil

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

root / drupal7 / sites / all / modules / views / modules / user / views_handler_field_user.inc @ b08fce64

1
<?php
2

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

    
8
/**
9
 * Field handler to provide simple renderer that allows linking to a user.
10
 *
11
 * @ingroup views_field_handlers
12
 */
13
class views_handler_field_user extends views_handler_field {
14
  /**
15
   * Override init function to provide generic option to link to user.
16
   */
17
  function init(&$view, &$data) {
18
    parent::init($view, $data);
19
    if (!empty($this->options['link_to_user'])) {
20
      $this->additional_fields['uid'] = 'uid';
21
    }
22
  }
23

    
24
  function option_definition() {
25
    $options = parent::option_definition();
26
    $options['link_to_user'] = array('default' => TRUE, 'bool' => TRUE);
27
    return $options;
28
  }
29

    
30
  /**
31
   * Provide link to node option
32
   */
33
  function options_form(&$form, &$form_state) {
34
    $form['link_to_user'] = array(
35
      '#title' => t('Link this field to its user'),
36
      '#description' => t("Enable to override this field's links."),
37
      '#type' => 'checkbox',
38
      '#default_value' => $this->options['link_to_user'],
39
    );
40
    parent::options_form($form, $form_state);
41
  }
42

    
43
  function render_link($data, $values) {
44
    if (!empty($this->options['link_to_user']) && user_access('access user profiles') && ($uid = $this->get_value($values, 'uid')) && $data !== NULL && $data !== '') {
45
      $this->options['alter']['make_link'] = TRUE;
46
      $this->options['alter']['path'] = "user/" . $uid;
47
    }
48
    return $data;
49
  }
50

    
51
  function render($values) {
52
    $value = $this->get_value($values);
53
    return $this->render_link($this->sanitize_value($value), $values);
54
  }
55
}