3 namespace Drupal\video_embed_field\Plugin\video_embed_field\Provider;
5 use Drupal\video_embed_field\ProviderPluginBase;
8 * A Vimeo provider plugin.
10 * @VideoEmbedProvider(
12 * title = @Translation("Vimeo")
15 class Vimeo extends ProviderPluginBase {
20 public function renderEmbedCode($width, $height, $autoplay) {
22 '#type' => 'video_embed_iframe',
23 '#provider' => 'vimeo',
24 '#url' => sprintf('https://player.vimeo.com/video/%s', $this->getVideoId()),
26 'autoplay' => $autoplay,
32 'allowfullscreen' => 'allowfullscreen',
35 if ($time_index = $this->getTimeIndex()) {
36 $iframe['#fragment'] = sprintf('t=%s', $time_index);
44 public function getRemoteThumbnailUrl() {
45 return $this->oEmbedData()->thumbnail_url;
49 * Get the vimeo oembed data.
52 * An array of data from the oembed endpoint.
54 protected function oEmbedData() {
55 return json_decode(file_get_contents('http://vimeo.com/api/oembed.json?url=' . $this->getInput()));
61 public static function getIdFromInput($input) {
62 preg_match('/^https?:\/\/(www\.)?vimeo.com\/(channels\/[a-zA-Z0-9]*\/)?(?<id>[0-9]*)(\/[a-zA-Z0-9]+)?(\#t=(\d+)s)?$/', $input, $matches);
63 return isset($matches['id']) ? $matches['id'] : FALSE;
67 * Get the time index from the URL.
69 * @return string|FALSE
70 * A time index parameter to pass to the frame or FALSE if none is found.
72 protected function getTimeIndex() {
73 preg_match('/\#t=(?<time_index>(\d+)s)$/', $this->input, $matches);
74 return isset($matches['time_index']) ? $matches['time_index'] : FALSE;
80 public function getName() {
81 return $this->oEmbedData()->title;