You are here

public function BlazyVideoTrait::getVideoId in Blazy 7

Returns Youtube/ Vimeo video ID from URL, thanks to Kus from s.o.

2 calls to BlazyVideoTrait::getVideoId()
BlazyVideoTrait::getVideoEmbedUrl in src/Plugin/Field/FieldFormatter/BlazyVideoTrait.php
Returns Youtube/ Vimeo video embed suitable for non-file-entity.
BlazyVideoTrait::getVideoThumbnail in src/Plugin/Field/FieldFormatter/BlazyVideoTrait.php
Returns video thumbnail based on video id, needed by BlazyFilter.

File

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

Class

BlazyVideoTrait
A Trait common for Media integration with field details.

Namespace

Drupal\blazy\Plugin\Field\FieldFormatter

Code

public function getVideoId($url) {
  $parts = parse_url($url);
  if (isset($parts['query'])) {
    parse_str($parts['query'], $qs);
    if (isset($qs['v'])) {
      return $qs['v'];
    }
    elseif (isset($qs['vi'])) {
      return $qs['vi'];
    }
  }
  if (isset($parts['path'])) {
    $path = explode('/', trim($parts['path'], '/'));
    return $path[count($path) - 1];
  }
  return FALSE;
}