You are here

public function Instagram::renderEmbedCode in Video 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/video/Provider/Instagram.php \Drupal\video\Plugin\video\Provider\Instagram::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/Instagram.php, line 23

Class

Instagram
Plugin annotation @VideoEmbeddableProvider( id = "instagram", label = @Translation("Instagram"), description = @Translation("Instagram Video Provider"), regular_expressions = { "@^.*?instagram\.com\/p\/(?<id>(.*?))[\/]?$@i", }, …

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' => '100%',
      'frameborder' => '0',
      'allowfullscreen' => 'allowfullscreen',
      'src' => sprintf('//instagram.com/p/%s/embed/?autoplay=%d', $data['id'], $settings['autoplay']),
    ],
    '0' => [
      '#type' => 'html_tag',
      '#tag' => 'script',
      '#attributes' => [
        'type' => 'text/javascript',
        'src' => '//platform.instagram.com/en_US/embeds.js',
        'async',
        'defer',
      ],
      '#value' => '',
    ],
  ];
}