5 * Contains \Drupal\video\Plugin\video\Provider\Facebook.
8 namespace Drupal\video\Plugin\video\Provider;
10 use Drupal\video\ProviderPluginBase;
13 * @VideoEmbeddableProvider(
15 * label = @Translation("Facebook"),
16 * description = @Translation("Facebook Video Provider"),
17 * regular_expressions = {
18 * "@^https?://www\.facebook\.com/.*(/videos/(?<id>\d+))@i",
19 * "@^https?://www\.facebook\.com/.*(video\.php\?v=(?<id>\d+))@i"
21 * mimetype = "video/facebook",
22 * stream_wrapper = "facebook"
26 class Facebook extends ProviderPluginBase {
30 public function renderEmbedCode($settings) {
31 $file = $this->getVideoFile();
32 $data = $this->getVideoMetadata();
33 // @see https://developers.facebook.com/docs/plugins/embedded-video-player
35 '#type' => 'html_tag',
38 '#type' => 'html_tag',
40 '#value' => 'window.fbAsyncInit = function() {
45 }; (function(d, s, id){
46 var js, fjs = d.getElementsByTagName(s)[0];
47 if (d.getElementById(id)) {return;}
48 js = d.createElement(s); js.id = id;
49 js.src = "//connect.facebook.net/en_US/sdk.js";
50 fjs.parentNode.insertBefore(js, fjs);
51 }(document, \'script\', \'facebook-jssdk\'));',
54 '#type' => 'html_tag',
56 '#attributes' => array(
57 'class' => 'fb-video',
58 'data-href' => sprintf('https://www.facebook.com/video.php?v=%s', $data['id']),
59 'data-width' => $settings['width'],
60 'data-autoplay' => $settings['autoplay'] ? 1 : 0
69 public function getRemoteThumbnailUrl() {
70 $data = $this->getVideoMetadata();
71 return 'https://graph.facebook.com/' . $data['id'] . '/picture';