You are here

public function views_handler_field_user_name::render_link in Views (for Drupal 7) 7.3

Same name and namespace in other branches
  1. 6.3 modules/user/views_handler_field_user_name.inc \views_handler_field_user_name::render_link()
  2. 6.2 modules/user/views_handler_field_user_name.inc \views_handler_field_user_name::render_link()

Overrides views_handler_field_user::render_link

File

modules/user/views_handler_field_user_name.inc, line 62
Definition of views_handler_field_user_name.

Class

views_handler_field_user_name
Field handler for a simple renderer that allows using a themed user link.

Code

public function render_link($data, $values) {
  $account = new stdClass();
  $account->uid = $this
    ->get_value($values, 'uid');
  $account->name = $this
    ->get_value($values);

  // If we don't have a UID, we can't format anything.
  if (!isset($account->uid)) {
    return $data;
  }
  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,
      ));
    }
  }

  // If we want a formatted username, do that.
  if (!empty($this->options['format_username']) && !is_null($account->uid)) {
    return format_username($account);
  }

  // Otherwise, there's no special handling, so return the data directly.
  return $data;
}