You are here

public function BlazyFilter::getImageItemFromIframeSrc in Blazy 8.2

Returns the faked image item from SRC.

Parameters

array $settings: The content array being modified.

object $node: The HTML DOM object.

string $src: The corrected SRC value.

Return value

object The faked or file entity image item.

Overrides BlazyFilterInterface::getImageItemFromIframeSrc

1 call to BlazyFilter::getImageItemFromIframeSrc()
BlazyFilter::buildImageItem in src/Plugin/Filter/BlazyFilter.php
Returns the faked image item for the image, uploaded or hard-coded.

File

src/Plugin/Filter/BlazyFilter.php, line 471

Class

BlazyFilter
Provides a filter to lazyload image, or iframe elements.

Namespace

Drupal\blazy\Plugin\Filter

Code

public function getImageItemFromIframeSrc(array &$settings, &$node, $src) {

  // Iframe with data: alike scheme is a serious kidding, strip it earlier.
  $settings['input_url'] = $src;
  $this->blazyOembed
    ->checkInputUrl($settings);
  $data['item'] = NULL;

  // @todo figure out to not hard-code `field_media_oembed_video`.
  if (!empty($settings['is_media_library'])) {
    $media = $this->blazyManager
      ->getEntityTypeManager()
      ->getStorage('media')
      ->loadByProperties([
      'field_media_oembed_video' => $settings['input_url'],
    ]);
    $media = reset($media);
  }

  // We have media entity.
  if (isset($media) && $media) {
    $data['settings'] = $settings;
    $this->blazyOembed
      ->getMediaItem($data, $media);

    // Update data with local image.
    $settings = array_merge($settings, $data['settings']);
  }
  else {
    $data['item'] = $this->blazyOembed
      ->getExternalImageItem($settings);

    // Runs after type, width and height set, if any, to not recheck them.
    $this->blazyOembed
      ->build($settings);
  }
  return $data['item'];
}