You are here

public static function BlazyMedia::getMediaData in Blazy 7

Returns the preprocessed/ formatted variables based on media settings.

Known working media integration: Youtube, Vimeo. Others might differ.

1 call to BlazyMedia::getMediaData()
BlazyVideoTrait::getMediaItem in src/Plugin/Field/FieldFormatter/BlazyVideoTrait.php
Gets the Media item thumbnail, or re-associate the file entity to ME.

File

src/BlazyMedia.php, line 141

Class

BlazyMedia
Provides extra utilities to work with Media.

Namespace

Drupal\blazy

Code

public static function getMediaData(array $settings = []) {
  if (!isset(static::$mediaData[hash('md2', $settings['media_uri'])])) {
    $media_settings = self::getMediaSettings($settings);
    $scheme = $settings['scheme'];
    $theme_function = 'media_' . $scheme . '_theme';
    if ($media_settings && is_callable($theme_function)) {

      // Safe to use ctools, since file_entity depends on it.
      ctools_include('media_' . $scheme . '.theme', 'media_' . $scheme, 'themes');
      $function = 'media_' . $scheme . '_preprocess_media_' . $scheme . '_video';
      if (is_callable($function)) {
        $media_settings['captions'] = 0;
        $variables = [
          'options' => $media_settings,
          'uri' => $settings['media_uri'],
        ];

        // @todo compare against Slick 2.x, #3084848#comment-13283135.
        $function($variables);

        // Allows local devs or sites without SSL to still work.
        $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
        $variables['url'] = str_replace([
          'http://',
          'https://',
        ], $protocol . '://', $variables['url']);
        static::$mediaData[hash('md2', $settings['media_uri'])] = $variables;
      }
    }
  }
  return static::$mediaData[hash('md2', $settings['media_uri'])];
}