You are here

private function BlazyManager::buildMedia in Blazy 7

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

Build out (Responsive) image.

1 call to BlazyManager::buildMedia()
BlazyManager::prepareImage in src/BlazyManager.php
Prepares the Blazy image as a structured array ready for ::renderer().

File

src/BlazyManager.php, line 193

Class

BlazyManager
Implements a public facing blazy manager.

Namespace

Drupal\blazy

Code

private function buildMedia(array &$element, array &$build) {
  $item = $build['item'];
  $settings =& $build['settings'];
  $attributes =& $build['attributes'];

  // (Responsive) image with item attributes, might be RDF.
  $item_attributes = empty($build['item_attributes']) ? [] : Blazy::sanitize($build['item_attributes']);

  // Provides image attributes, also for Picture.
  Blazy::imageAttributes($item_attributes, $settings, $item);

  // Picture integration.
  if (!empty($settings['resimage'])) {
    $this
      ->buildResponsiveImage($attributes, $settings);
  }

  // If no picture found.
  if (empty($settings['picture'])) {
    $this
      ->buildImage($attributes, $item_attributes, $settings, $item);
  }

  // Provides media type and switcher attributes for JS works.
  $attributes['class'][] = 'media--' . $settings['type'];
  if ($settings['media_switch']) {
    $attributes['class'][] = 'media--switch media--switch--' . str_replace('_', '-', $settings['media_switch']);
  }
  $element['#item_attributes'] = $item_attributes;
}