You are here

public function Twitter::html in Video Filter 8

HTML code of the video player.

Overrides VideoFilterBase::html

File

src/Plugin/VideoFilter/Twitter.php, line 24

Class

Twitter
Provides Twitter codec for Video Filter.

Namespace

Drupal\video_filter\Plugin\VideoFilter

Code

public function html($video) {

  // Get embed code via oEmbed.
  $endpoint = 'https://api.twitter.com/1/statuses/oembed.json?url=https://twitter.com/' . $video['codec']['matches'][1] . '/status/' . $video['codec']['matches'][2];
  $request = \Drupal::httpClient()
    ->get($endpoint, [
    'headers' => [
      'Accept' => 'application/json',
    ],
  ]);
  if ($request
    ->getStatusCode() == 200) {
    $response = json_decode($request
      ->getBody());
  }
  $html = !empty($response->html) ? $response->html : '';
  return $html;
}