You are here

function template_preprocess_sooperthemes_gridstack_gridstack_formatter in Sooperthemes GridStack 8

Prepares variables for gridstack formatter templates.

Default template: sooperthemes-gridstack-gridstack-formatter.html.twig.

Parameters

array $vars: An associative array containing:

  • item: An ImageItem object.
  • item_attributes: An optional associative array of html attributes to be placed in the img tag.
  • image_style: An optional image style.
  • url: An optional \Drupal\Core\Url object.

File

./theme.inc, line 24
Preprocess functions for SooperThemes GridStack module.

Code

function template_preprocess_sooperthemes_gridstack_gridstack_formatter(&$vars) {

  /** @var \Drupal\file\FileInterface $entity */
  $entity = $vars['item']->entity;
  $image_uri = $entity && empty($vars['item']->uri) ? $entity
    ->getFileUri() : $vars['item']->uri;
  $vars['image_url'] = $vars['image_style'] ? ImageStyle::load($vars['image_style'])
    ->buildUrl($image_uri) : file_create_url($image_uri);
}