Version 1
[yaffs-website] / web / modules / contrib / video / src / Plugin / video / Provider / Vimeo.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\video\Plugin\video\Provider\Vimeo.
6  */
7
8 namespace Drupal\video\Plugin\video\Provider;
9
10 use Drupal\video\ProviderPluginBase;
11
12 /**
13  * @VideoEmbeddableProvider(
14  *   id = "vimeo",
15  *   label = @Translation("Vimeo"),
16  *   description = @Translation("Vimeo Video Provider"),
17  *   regular_expressions = {
18  *     "/^https?:\/\/(www\.)?vimeo.com\/(?<id>[0-9]*)$/",
19  *   },
20  *   mimetype = "video/vimeo",
21  *   stream_wrapper = "vimeo"
22  * )
23  */
24
25 class Vimeo extends ProviderPluginBase {
26   
27   /**
28    * {@inheritdoc}
29    */
30   public function renderEmbedCode($settings) {
31     $file = $this->getVideoFile();
32     $data = $this->getVideoMetadata();
33     return [
34       '#type' => 'html_tag',
35       '#tag' => 'iframe',
36       '#attributes' => [
37         'width' => $settings['width'],
38         'height' => $settings['height'],
39         'frameborder' => '0',
40         'allowfullscreen' => 'allowfullscreen',
41         'src' => sprintf('https://player.vimeo.com/video/%s?autoplay=%d', $data['id'], $settings['autoplay']),
42       ],
43     ];
44   }
45   
46   /**
47    * {@inheritdoc}
48    */
49   public function getRemoteThumbnailUrl() {
50     $data = $this->getVideoMetadata();
51     $video_data = json_decode(file_get_contents('http://vimeo.com/api/v2/video/' . $data['id'] . '.json'));
52     return $video_data[0]->thumbnail_large;
53   }
54 }