Newer
Older
The Great Git Migration
committed
<?php
/**
* @file
* Definition of views_handler_field_user_name.
*/
The Great Git Migration
committed
/**
Damien McKenna
committed
* Field handler for a simple renderer that allows using a themed user link.
The Great Git Migration
committed
*/
class views_handler_field_user_name extends views_handler_field_user {
Damien McKenna
committed
/**
* {@inheritdoc}
*/
public function option_definition() {
The Great Git Migration
committed
$options = parent::option_definition();
Daniel Wehner
committed
$options['overwrite_anonymous'] = array('default' => FALSE, 'bool' => TRUE);
The Great Git Migration
committed
$options['anonymous_text'] = array('default' => '', 'translatable' => TRUE);
Daniel Wehner
committed
$options['format_username'] = array('default' => TRUE, 'bool' => TRUE);
The Great Git Migration
committed
return $options;
}
Damien McKenna
committed
/**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
$form['format_username'] = array(
'#title' => t('Use formatted username'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['format_username']),
'#description' => t('If checked, the username will be formatted by the system. If unchecked, it will be displayed raw.'),
'#fieldset' => 'more',
);
The Great Git Migration
committed
$form['overwrite_anonymous'] = array(
'#title' => t('Overwrite the value to display for anonymous users'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['overwrite_anonymous']),
Katherine Senzee
committed
'#description' => t('Enable to display different text for anonymous users.'),
'#fieldset' => 'more',
The Great Git Migration
committed
);
$form['anonymous_text'] = array(
'#title' => t('Text to display for anonymous users'),
'#type' => 'textfield',
'#default_value' => $this->options['anonymous_text'],
Daniel Wehner
committed
'#dependency' => array(
'edit-options-overwrite-anonymous' => array(1),
The Great Git Migration
committed
),
Katherine Senzee
committed
'#fieldset' => 'more',
The Great Git Migration
committed
);
Katherine Senzee
committed
parent::options_form($form, $form_state);
The Great Git Migration
committed
}
Damien McKenna
committed
/**
* {@inheritdoc}
*/
public function render_link($data, $values) {
$account = new stdClass();
$account->uid = $this->get_value($values, 'uid');
$account->name = $this->get_value($values);
The Great Git Migration
committed
if (!empty($this->options['link_to_user']) || !empty($this->options['overwrite_anonymous'])) {
if (!empty($this->options['overwrite_anonymous']) && !$account->uid) {
// This is an anonymous user, and we're overriting the text.
return check_plain($this->options['anonymous_text']);
}
elseif (!empty($this->options['link_to_user'])) {
$account->name = $this->get_value($values);
return theme('username', array('account' => $account));
The Great Git Migration
committed
}
}
// If we want a formatted username, do that.
MustangGB
committed
if (!empty($this->options['format_username']) && !is_null($account->uid)) {
return format_username($account);
}
The Great Git Migration
committed
// Otherwise, there's no special handling, so return the data directly.
return $data;
}
Damien McKenna
committed