commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / views / modules / user / views_handler_field_user_name.inc
1 <?php
2
3 /**
4 * @file
5 * Definition of views_handler_field_user_name.
6 */
7
8 /**
9 * Field handler to provide simple renderer that allows using a themed user link.
10 *
11 * @ingroup views_field_handlers
12 */
13 class views_handler_field_user_name extends views_handler_field_user {
14 /**
15 * Add uid in the query so we can test for anonymous if needed.
16 */
17 function init(&$view, &$data) {
18 parent::init($view, $data);
19 if (!empty($this->options['overwrite_anonymous']) || !empty($this->options['format_username'])) {
20 $this->additional_fields['uid'] = 'uid';
21 }
22 }
23
24 function option_definition() {
25 $options = parent::option_definition();
26
27 $options['overwrite_anonymous'] = array('default' => FALSE, 'bool' => TRUE);
28 $options['anonymous_text'] = array('default' => '', 'translatable' => TRUE);
29 $options['format_username'] = array('default' => TRUE, 'bool' => TRUE);
30
31 return $options;
32 }
33
34 function options_form(&$form, &$form_state) {
35 $form['format_username'] = array(
36 '#title' => t('Use formatted username'),
37 '#type' => 'checkbox',
38 '#default_value' => !empty($this->options['format_username']),
39 '#description' => t('If checked, the username will be formatted by the system. If unchecked, it will be displayed raw.'),
40 '#fieldset' => 'more',
41 );
42 $form['overwrite_anonymous'] = array(
43 '#title' => t('Overwrite the value to display for anonymous users'),
44 '#type' => 'checkbox',
45 '#default_value' => !empty($this->options['overwrite_anonymous']),
46 '#description' => t('Enable to display different text for anonymous users.'),
47 '#fieldset' => 'more',
48 );
49 $form['anonymous_text'] = array(
50 '#title' => t('Text to display for anonymous users'),
51 '#type' => 'textfield',
52 '#default_value' => $this->options['anonymous_text'],
53 '#dependency' => array(
54 'edit-options-overwrite-anonymous' => array(1),
55 ),
56 '#fieldset' => 'more',
57 );
58
59 parent::options_form($form, $form_state);
60 }
61
62 function render_link($data, $values) {
63 $account = new stdClass();
64 $account->uid = $this->get_value($values, 'uid');
65 $account->name = $this->get_value($values);
66 if (!empty($this->options['link_to_user']) || !empty($this->options['overwrite_anonymous'])) {
67 if (!empty($this->options['overwrite_anonymous']) && !$account->uid) {
68 // This is an anonymous user, and we're overriting the text.
69 return check_plain($this->options['anonymous_text']);
70 }
71 elseif (!empty($this->options['link_to_user'])) {
72 $account->name = $this->get_value($values);
73 return theme('username', array('account' => $account));
74 }
75 }
76 // If we want a formatted username, do that.
77 if (!empty($this->options['format_username'])) {
78 return format_username($account);
79 }
80 // Otherwise, there's no special handling, so return the data directly.
81 return $data;
82 }
83 }