You are here

public function BlazyFileFormatter::buildElement in Blazy 7

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldFormatter/BlazyFileFormatter.php \Drupal\blazy\Plugin\Field\FieldFormatter\BlazyFileFormatter::buildElement()

Build individual item if so configured such as for file entity goodness.

Overrides BlazyFormatterBlazy::buildElement

File

src/Plugin/Field/FieldFormatter/BlazyFileFormatter.php, line 42

Class

BlazyFileFormatter
Plugin implementation of the 'Blazy File' to get videos within images/files.

Namespace

Drupal\blazy\Plugin\Field\FieldFormatter

Code

public function buildElement(array &$element, $entity, $delta = 0) {
  $settings = $element['settings'];

  // Extract image item from file, and assign it to $element['item'] so that
  // Blazy can display an image along with video, or just mixed.
  if ($settings['type'] == 'video') {
    if ($image = $this
      ->getImageItem($entity)) {
      $element['item'] = $image['item'];
      $element['settings'] = array_merge($settings, $image['settings']);
    }
    $this
      ->getMediaItem($element, $entity);
  }
}