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