You are here

public function BlazyManager::preRenderBuild in Blazy 8.2

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

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

File

src/BlazyManager.php, line 479

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.
  $attributes = isset($element['#attributes']) ? $element['#attributes'] : [];
  $attributes = isset($element['#theme_wrappers'], $element['#theme_wrappers']['container']['#attributes']) ? $element['#theme_wrappers']['container']['#attributes'] : $attributes;
  $settings = $this
    ->getSettings($build);

  // Runs after ::getSettings.
  $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 not so 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 (isset($element['#ajax_replace_class'])) {
      $element['#container_attributes'] = $attributes;
    }
    else {

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