You are here

public static function BlazyMedia::build in Blazy 8

Same name and namespace in other branches
  1. 8.2 src/BlazyMedia.php \Drupal\blazy\BlazyMedia::build()
  2. 7 src/BlazyMedia.php \Drupal\blazy\BlazyMedia::build()

Builds the media field which cannot be displayed using theme_blazy().

Some use URLs from inputs, some local files.

Parameters

object $media: The media being rendered.

array $settings: The contextual settings array.

Return value

array|bool The renderable array of the media field, or false if not applicable.

3 calls to BlazyMedia::build()
BlazyFormatterTest::testBlazyMedia in tests/src/Kernel/BlazyFormatterTest.php
Tests the Blazy formatter faked Media integration.
BlazyMediaUnitTest::testBlazyMediaBuild in tests/src/Unit/BlazyMediaUnitTest.php
Tests \Drupal\blazy\BlazyMedia::build().
BlazyVideoTrait::getMediaItem in src/Dejavu/BlazyVideoTrait.php
Gets the Media item thumbnail, or re-associate the file entity to ME.

File

src/BlazyMedia.php, line 25

Class

BlazyMedia
Provides extra media utilities without dependencies on Media Entity, etc.

Namespace

Drupal\blazy

Code

public static function build($media, array $settings = []) {

  // Prevents fatal error with disconnected internet when having ME Facebook,
  // ME SlideShare, resorted to static thumbnails to avoid broken displays.
  if (!empty($settings['input_url'])) {

    // @todo: Remove when ME Facebook alike handles this.
    try {
      \Drupal::httpClient()
        ->get($settings['input_url']);
    } catch (\Exception $e) {
      return FALSE;
    }
  }
  $build = $media
    ->get($settings['source_field'])
    ->view($settings['view_mode']);
  $build['#settings'] = $settings;
  return isset($build[0]) ? self::wrap($build) : $build;
}