You are here

public function BlazyManager::preRenderBlazy in Blazy 8.2

Builds the Blazy image as a structured array ready for ::renderer().

Parameters

array $element: The pre-rendered element.

Return value

array The renderable array of pre-rendered element.

File

src/BlazyManager.php, line 75

Class

BlazyManager
Implements a public facing blazy manager.

Namespace

Drupal\blazy

Code

public function preRenderBlazy(array $element) {
  $build = $element['#build'];
  unset($element['#build']);

  // Prepare the main image.
  $this
    ->prepareBlazy($element, $build);

  // Fetch the newly modified settings.
  $settings = $element['#settings'];
  if (!empty($settings['media_switch'])) {
    if ($settings['media_switch'] == 'content' && !empty($settings['content_url'])) {
      $element['#url'] = $settings['content_url'];
    }
    elseif (!empty($settings['lightbox'])) {
      BlazyLightbox::build($element);
    }
  }
  return $element;
}