You are here

function Picture::render in Views (for Drupal 7) 8.3

Render the field.

Parameters

$values: The values retrieved from the database.

Overrides FieldPluginBase::render

File

lib/Views/user/Plugin/views/field/Picture.php, line 92
Definition of Views\user\Plugin\views\field\Picture.

Class

Picture
Field handler to provide simple renderer that allows using a themed user link.

Namespace

Views\user\Plugin\views\field

Code

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);
      $picture_filepath = $picture->uri;
    }
    else {
      $picture_filepath = variable_get('user_picture_default', '');
    }
    if (file_valid_uri($picture_filepath)) {
      $output = theme('image_style', array(
        'style_name' => $this->options['image_style'],
        'path' => $picture_filepath,
      ));
      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 = entity_create('user', array());
    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;
}