You are here

public function BlazyStylePluginTrait::getImageItem in Blazy 8

Same name and namespace in other branches
  1. 8.2 src/Dejavu/BlazyStylePluginTrait.php \Drupal\blazy\Dejavu\BlazyStylePluginTrait::getImageItem()
  2. 7 src/Dejavu/BlazyStylePluginTrait.php \Drupal\blazy\Dejavu\BlazyStylePluginTrait::getImageItem()

Get the image item to work with out of this formatter.

All this mess is because Views may render/flatten images earlier.

3 calls to BlazyStylePluginTrait::getImageItem()
BlazyStylePluginBase::buildElement in src/Dejavu/BlazyStylePluginBase.php
Returns an individual row/element content.
BlazyStylePluginTrait::getImageRenderable in src/Dejavu/BlazyStylePluginTrait.php
Returns the modified renderable image_formatter to support lazyload.
BlazyStylePluginTrait::isImageRenderable in src/Dejavu/BlazyStylePluginTrait.php
Checks if we can work with this formatter, otherwise no go if flattened.

File

src/Dejavu/BlazyStylePluginTrait.php, line 206

Class

BlazyStylePluginTrait
A Trait common for optional views style plugins.

Namespace

Drupal\blazy\Dejavu

Code

public function getImageItem($image) {
  $item = [];

  // Image formatter.
  if (isset($image['raw'])) {
    $item = empty($image['rendered']['#item']) ? [] : $image['rendered']['#item'];

    // Blazy formatter.
    if (isset($image['rendered']['#build'])) {
      $item = $image['rendered']['#build']['item'];
    }
  }

  // Don't know other reasonable formatters to work with.
  if (!is_object($item)) {
    return [];
  }
  return $item;
}