You are here

public function YouTube::renderEmbedCode in Video 8

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

Render embed code.

Parameters

string $settings: The settings of the video player.

Return value

mixed A renderable array of the embed code.

Overrides ProviderPluginInterface::renderEmbedCode

File

src/Plugin/video/Provider/YouTube.php, line 28

Class

YouTube
Plugin annotation @VideoEmbeddableProvider( id = "youtube", label = @Translation("YouTube"), description = @Translation("YouTube Video Provider"), regular_expressions = { …

Namespace

Drupal\video\Plugin\video\Provider

Code

public function renderEmbedCode($settings) {
  $file = $this
    ->getVideoFile();
  $data = $this
    ->getVideoMetadata();
  return [
    '#type' => 'html_tag',
    '#tag' => 'iframe',
    '#attributes' => [
      'width' => $settings['width'],
      'height' => $settings['height'],
      'frameborder' => '0',
      'allowfullscreen' => 'allowfullscreen',
      'src' => sprintf('https://www.youtube.com/embed/%s?autoplay=%d&rel=%d&start=%d', $data['id'], $settings['autoplay'], $settings['related_videos'], NULL),
    ],
  ];
}