You are here

public function BlazyEntityMediaBase::buildElements in Blazy 8.2

Returns media contents.

Overrides BlazyEntityBase::buildElements

1 call to BlazyEntityMediaBase::buildElements()
BlazyTestEntityReferenceFormatterTest::viewElements in tests/modules/blazy_test/src/Plugin/Field/FieldFormatter/BlazyTestEntityReferenceFormatterTest.php
Builds a renderable array for a field value.

File

src/Dejavu/BlazyEntityMediaBase.php, line 36

Class

BlazyEntityMediaBase
Base class for Media entity reference formatters with field details.

Namespace

Drupal\blazy\Dejavu

Code

public function buildElements(array &$build, $entities, $langcode) {
  parent::buildElements($build, $entities, $langcode);
  $settings =& $build['settings'];
  $item_id = $settings['item_id'];

  // Some formatter has a toggle Vanilla.
  if (empty($settings['vanilla'])) {
    $settings['check_blazy'] = TRUE;

    // Supports Blazy formatter multi-breakpoint images if available.
    if (isset($build['items'][0]) && ($item = $build['items'][0])) {
      $fallback = isset($item[$item_id]['#build']) ? $item[$item_id]['#build'] : [];
      $settings['first_image'] = isset($item['#build']) ? $item['#build'] : $fallback;
    }
  }
}