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
|
/**
|
16
|
* Override init function to provide generic option to link to user.
|
17
|
*/
|
18
|
public function init(&$view, &$data) {
|
19
|
parent::init($view, $data);
|
20
|
if (!empty($this->options['link_to_user'])) {
|
21
|
$this->additional_fields['uid'] = 'uid';
|
22
|
}
|
23
|
}
|
24
|
|
25
|
/**
|
26
|
* {@inheritdoc}
|
27
|
*/
|
28
|
public function option_definition() {
|
29
|
$options = parent::option_definition();
|
30
|
$options['link_to_user'] = array('default' => TRUE, 'bool' => TRUE);
|
31
|
return $options;
|
32
|
}
|
33
|
|
34
|
/**
|
35
|
* Provide link to node option.
|
36
|
*/
|
37
|
public function options_form(&$form, &$form_state) {
|
38
|
$form['link_to_user'] = array(
|
39
|
'#title' => t('Link this field to its user'),
|
40
|
'#description' => t("Enable to override this field's links."),
|
41
|
'#type' => 'checkbox',
|
42
|
'#default_value' => $this->options['link_to_user'],
|
43
|
);
|
44
|
parent::options_form($form, $form_state);
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
* {@inheritdoc}
|
49
|
*/
|
50
|
public function render_link($data, $values) {
|
51
|
if (!empty($this->options['link_to_user']) && user_access('access user profiles') && ($uid = $this->get_value($values, 'uid')) && $data !== NULL && $data !== '') {
|
52
|
$this->options['alter']['make_link'] = TRUE;
|
53
|
$this->options['alter']['path'] = "user/" . $uid;
|
54
|
}
|
55
|
return $data;
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* {@inheritdoc}
|
60
|
*/
|
61
|
public function render($values) {
|
62
|
$value = $this->get_value($values);
|
63
|
return $this->render_link($this->sanitize_value($value), $values);
|
64
|
}
|
65
|
|
66
|
}
|