class GoogleDrive in Video Embed Google Drive 8
A Google Drive provider plugin for video embed field.
Plugin annotation
@VideoEmbedProvider(
id = "google_drive",
title = @Translation("Google Drive")
)
Hierarchy
- class \Drupal\video_embed_google_drive\Plugin\video_embed_field\Provider\GoogleDrive extends \Drupal\video_embed_field\ProviderPluginBase
Expanded class hierarchy of GoogleDrive
File
- src/
Plugin/ video_embed_field/ Provider/ GoogleDrive.php, line 15
Namespace
Drupal\video_embed_google_drive\Plugin\video_embed_field\ProviderView source
class GoogleDrive extends ProviderPluginBase {
/**
* {@inheritdoc}
*/
public static function getIdFromInput($input) {
preg_match('/^https?:\\/\\/drive.google.com\\/(file\\/d\\/|open\\?id=)(?<id>[0-9a-zA-Z-_]{2,64}).*$/', $input, $matches);
return isset($matches['id']) ? $matches['id'] : FALSE;
}
/**
* {@inheritdoc}
*/
public function renderEmbedCode($width, $height, $autoplay) {
$iframe = [
'#type' => 'video_embed_iframe',
'#provider' => 'google_drive',
'#url' => sprintf('https://drive.google.com/file/d/%s/preview', $this
->getVideoId()),
'#query' => [],
'#attributes' => [
'width' => $width,
'height' => $height,
'frameborder' => '0',
'allowfullscreen' => 'allowfullscreen',
],
];
// TODO: is this supported by google drive?
// if ($time_index = $this->getTimeIndex()) {
// $iframe['#fragment'] = sprintf('t=%s', $time_index);
// }
return $iframe;
}
/**
* {@inheritdoc}
*/
public function getRemoteThumbnailUrl() {
$url = 'https://drive.google.com/thumbnail?authuser=0&sz=w320&id=%s';
return sprintf($url, $this
->getVideoId());
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GoogleDrive:: |
public static | function | ||
GoogleDrive:: |
public | function | ||
GoogleDrive:: |
public | function |