commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / views / modules / comment / views_handler_field_comment_username.inc
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 * Override init function to add uid and homepage fields.
16 */
17 function init(&$view, &$data) {
18 parent::init($view, $data);
19 $this->additional_fields['uid'] = 'uid';
20 $this->additional_fields['homepage'] = 'homepage';
21 }
22
23 function option_definition() {
24 $options = parent::option_definition();
25 $options['link_to_user'] = array('default' => TRUE, 'bool' => TRUE);
26 return $options;
27 }
28
29 function options_form(&$form, &$form_state) {
30 $form['link_to_user'] = array(
31 '#title' => t("Link this field to its user or an author's homepage"),
32 '#type' => 'checkbox',
33 '#default_value' => $this->options['link_to_user'],
34 );
35 parent::options_form($form, $form_state);
36 }
37
38 function render_link($data, $values) {
39 if (!empty($this->options['link_to_user'])) {
40 $account = new stdClass();
41 $account->uid = $this->get_value($values, 'uid');
42 $account->name = $this->get_value($values);
43 $account->homepage = $this->get_value($values, 'homepage');
44
45 return theme('username', array(
46 'account' => $account
47 ));
48 }
49 else {
50 return $data;
51 }
52 }
53
54 function render($values) {
55 $value = $this->get_value($values);
56 return $this->render_link($this->sanitize_value($value), $values);
57 }
58 }