You are here

public function views_handler_field_user_picture::render in Views (for Drupal 7) 7.3

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

Render the field.

Parameters

array $values: The values retrieved from the database.

Overrides views_handler_field::render

File

modules/user/views_handler_field_user_picture.inc, line 92
Definition of views_handler_field_user_picture.

Class

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

Code

public function render($values) {
  if ($this->options['image_style'] && module_exists('image')) {

    // @todo Switch to always using theme('user_picture') when it starts
    // supporting image styles. See http://drupal.org/node/1021564
    if ($picture_fid = $this
      ->get_value($values)) {
      $picture = file_load($picture_fid);
      if (!empty($picture)) {
        $picture_filepath = $picture->uri;
      }
      else {
        $picture_filepath = variable_get('user_picture_default', '');
      }
    }
    else {
      $picture_filepath = variable_get('user_picture_default', '');
    }
    if (file_valid_uri($picture_filepath)) {
      $account = user_load($this
        ->get_value($values, 'uid'));
      $alt = t("@user's picture", array(
        '@user' => format_username($account),
      ));
      $output = theme('image_style', array(
        'style_name' => $this->options['image_style'],
        'path' => $picture_filepath,
        'alt' => $alt,
      ));
      if ($this->options['link_photo_to_profile'] && user_access('access user profiles')) {
        $uid = $this
          ->get_value($values, 'uid');
        $output = l($output, "user/{$uid}", array(
          'html' => TRUE,
        ));
      }
    }
    else {
      $output = '';
    }
  }
  else {

    // Fake an account object.
    $account = new stdClass();
    if ($this->options['link_photo_to_profile']) {

      // Prevent template_preprocess_user_picture from adding a link
      // by not setting the uid.
      $account->uid = $this
        ->get_value($values, 'uid');
    }
    $account->name = $this
      ->get_value($values, 'name');
    $account->mail = $this
      ->get_value($values, 'mail');
    $account->picture = $this
      ->get_value($values);
    $output = theme('user_picture', array(
      'account' => $account,
    ));
  }
  return $output;
}