Newer
Older
The Great Git Migration
committed
<?php
/**
* @file
* Definition of views_handler_field_user.
*/
The Great Git Migration
committed
/**
* Field handler to provide simple renderer that allows linking to a user.
The Great Git Migration
committed
*/
class views_handler_field_user extends views_handler_field {
Damien McKenna
committed
The Great Git Migration
committed
/**
* Override init function to provide generic option to link to user.
*/
Damien McKenna
committed
public function init(&$view, &$data) {
The Great Git Migration
committed
parent::init($view, $data);
if (!empty($this->options['link_to_user'])) {
$this->additional_fields['uid'] = 'uid';
}
}
Damien McKenna
committed
/**
* {@inheritdoc}
*/
public function option_definition() {
The Great Git Migration
committed
$options = parent::option_definition();
Daniel Wehner
committed
$options['link_to_user'] = array('default' => TRUE, 'bool' => TRUE);
The Great Git Migration
committed
return $options;
}
/**
Damien McKenna
committed
* Provide link to node option.
The Great Git Migration
committed
*/
Damien McKenna
committed
public function options_form(&$form, &$form_state) {
The Great Git Migration
committed
$form['link_to_user'] = array(
'#title' => t('Link this field to its user'),
Katherine Senzee
committed
'#description' => t("Enable to override this field's links."),
The Great Git Migration
committed
'#type' => 'checkbox',
'#default_value' => $this->options['link_to_user'],
);
Katherine Senzee
committed
parent::options_form($form, $form_state);
The Great Git Migration
committed
}
Damien McKenna
committed
/**
* {@inheritdoc}
*/
public function render_link($data, $values) {
Daniel Wehner
committed
if (!empty($this->options['link_to_user']) && user_access('access user profiles') && ($uid = $this->get_value($values, 'uid')) && $data !== NULL && $data !== '') {
The Great Git Migration
committed
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "user/" . $uid;
The Great Git Migration
committed
}
return $data;
}
Damien McKenna
committed
/**
* {@inheritdoc}
*/
public function render($values) {
$value = $this->get_value($values);
return $this->render_link($this->sanitize_value($value), $values);
The Great Git Migration
committed
}
Damien McKenna
committed