You are here

public function YouTube::renderEmbedCode in Video Embed Field 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/video_embed_field/Provider/YouTube.php \Drupal\video_embed_field\Plugin\video_embed_field\Provider\YouTube::renderEmbedCode()

Render embed code.

Parameters

string $width: The width of the video player.

string $height: The height of the video player.

bool $autoplay: If the video should autoplay.

Return value

mixed A renderable array of the embed code.

Overrides ProviderPluginInterface::renderEmbedCode

File

src/Plugin/video_embed_field/Provider/YouTube.php, line 20

Class

YouTube
A YouTube provider plugin.

Namespace

Drupal\video_embed_field\Plugin\video_embed_field\Provider

Code

public function renderEmbedCode($width, $height, $autoplay) {
  $embed_code = [
    '#type' => 'video_embed_iframe',
    '#provider' => 'youtube',
    '#url' => sprintf('https://www.youtube.com/embed/%s', $this
      ->getVideoId()),
    '#query' => [
      'autoplay' => $autoplay,
      'start' => $this
        ->getTimeIndex(),
      'rel' => '0',
    ],
    '#attributes' => [
      'width' => $width,
      'height' => $height,
      'frameborder' => '0',
      'allowfullscreen' => 'allowfullscreen',
    ],
  ];
  if ($language = $this
    ->getLanguagePreference()) {
    $embed_code['#query']['cc_lang_pref'] = $language;
  }
  return $embed_code;
}