You are here

public function BlazyManager::preRenderBuild in Blazy 7

Same name and namespace in other branches
  1. 8.2 src/BlazyManager.php \Drupal\blazy\BlazyManager::preRenderBuild()

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

File

src/BlazyManager.php, line 389

Class

BlazyManager
Implements a public facing blazy manager.

Namespace

Drupal\blazy

Code

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

  // Checks if we got some signaled attributes.
  $commerce = isset($element['#ajax_replace_class']);
  $attributes = isset($element['#attributes']) ? $element['#attributes'] : [];
  $attributes = isset($element['#theme_wrappers'], $element['#theme_wrappers']['container']['#attributes']) ? $element['#theme_wrappers']['container']['#attributes'] : $attributes;
  $settings = $this
    ->prepareBuild($build);

  // Take over elements for a grid display as this is all we need, learned
  // from the issues such as: #2945524, or product variations.
  // We'll selectively pass or work out $attributes far below.
  $element = BlazyGrid::build($build, $settings);
  $this
    ->setAttachments($element, $settings);
  if ($attributes) {

    // Signals other modules if they want to use it.
    // Cannot merge it into BlazyGrid (wrapper_)attributes, done as grid.
    // Use case: Product variations, best served by ElevateZoom Plus.
    if ($commerce) {
      $element['#container_attributes'] = $attributes;
    }
    else {

      // Use case: VIS, can be blended with UL element safely down here.
      $element['#attributes'] = NestedArray::mergeDeep($element['#attributes'], $attributes);
    }
  }
  return $element;
}