You are here

public function BlazyManager::preRender in Blazy 7

Builds the Blazy 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 100

Class

BlazyManager
Implements a public facing blazy manager.

Namespace

Drupal\blazy

Code

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

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

  // Fetch the newly modified settings.
  $settings =& $element['#settings'];

  // Provides optional media video if so configured.
  // Does it look familiar, `module_load_include()`, only native?
  // Allows a hybrid of media switcher and quasi-lightbox like Zooming, etc.
  if ($settings['use_media'] && empty($settings['_noiframe'])) {
    BlazyMedia::build($element);
  }

  // Image is optional for Video, and Blazy CSS background images.
  // Must run after image or video setups.
  if ($settings['background']) {
    $settings['use_image'] = FALSE;
  }

  // Provides optional link to content or lightboxes if so configured.
  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;
}