You are here

public function ViewsSystemScreenshot::render in Views System 8

Renders the field.

Parameters

\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.

Return value

string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.

Overrides FieldPluginBase::render

File

src/Plugin/views/field/ViewsSystemScreenshot.php, line 76
Contains \Drupal\views_system\Plugin\views\field\ViewsSystemScreenshot.

Class

ViewsSystemScreenshot
Field handler to display the thumbnail image of a theme.

Namespace

Drupal\views_system\Plugin\views\field

Code

public function render(ResultRow $values) {
  $value = $values->{$this->field_alias};
  if (!$this->options['image']) {
    return $value;
  }
  if (!empty($value)) {
    $screenshot = array(
      '#theme' => 'image',
      '#uri' => $value,
      '#alt' => t('Screenshot'),
      '#title' => t('Screenshot'),
      '#width' => $this->options['image_width'],
      '#height' => $this->options['image_height'],
      '#attributes' => array(
        'class' => array(
          'screenshot',
        ),
      ),
    );
  }
  else {
    $screenshot = array(
      '#theme' => 'image',
      '#uri' => drupal_get_path('module', 'system') . '/images/no_screenshot.png',
      '#alt' => t('No screenshot'),
      '#title' => t('No screenshot'),
      '#width' => $this->options['image_width'],
      '#height' => $this->options['image_height'],
      '#attributes' => array(
        'class' => array(
          'no-screenshot',
        ),
      ),
    );
  }
  return \Drupal::service('renderer')
    ->render($screenshot);
}