You are here

public function BlazyVideoTrait::getVideoEmbedUrl in Blazy 7

Returns Youtube/ Vimeo video embed suitable for non-file-entity.

@todo deprecate this for media WYSIWG via BlazyMedia::getMediaData(). Still relevant for BlazyFilter UGC, though, till merged with media WYSIWYG.

1 call to BlazyVideoTrait::getVideoEmbedUrl()
BlazyFilter::buildImageItem in src/Plugin/Filter/BlazyFilter.php

File

src/Plugin/Field/FieldFormatter/BlazyVideoTrait.php, line 207

Class

BlazyVideoTrait
A Trait common for Media integration with field details.

Namespace

Drupal\blazy\Plugin\Field\FieldFormatter

Code

public function getVideoEmbedUrl($url) {
  if ($vid = $this
    ->getVideoId($url)) {
    $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
    if (strpos($url, 'youtu') !== FALSE) {
      return $protocol . '://www.youtube.com/embed/' . $vid;
    }
    elseif (strpos($url, 'vimeo') !== FALSE) {
      return $protocol . '://player.vimeo.com/video/' . $vid;
    }
  }
  return '';
}