You are here

public function Vimeo::renderEmbedCode in Video Embed Field 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/video_embed_field/Provider/Vimeo.php \Drupal\video_embed_field\Plugin\video_embed_field\Provider\Vimeo::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/Vimeo.php, line 20

Class

Vimeo
A Vimeo provider plugin.

Namespace

Drupal\video_embed_field\Plugin\video_embed_field\Provider

Code

public function renderEmbedCode($width, $height, $autoplay) {
  $iframe = [
    '#type' => 'video_embed_iframe',
    '#provider' => 'vimeo',
    '#url' => sprintf('https://player.vimeo.com/video/%s', $this
      ->getVideoId()),
    '#query' => [
      'autoplay' => $autoplay,
    ],
    '#attributes' => [
      'width' => $width,
      'height' => $height,
      'frameborder' => '0',
      'allowfullscreen' => 'allowfullscreen',
    ],
  ];
  if ($time_index = $this
    ->getTimeIndex()) {
    $iframe['#fragment'] = sprintf('t=%s', $time_index);
  }
  return $iframe;
}