Loading README.md +1 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ Supported providers / Formatters included: - Apple Podcasts - Box - Brightcove - Buzzsprout - Dacast - Deezer Loading config/schema/media_remote.schema.yml +8 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,14 @@ field.formatter.settings.media_remote_box: type: string label: 'Iframe height' field.formatter.settings.media_remote_brightcove: type: mapping label: 'Brightcove display format settings' mapping: formatter_class: type: string label: 'Formatter class name' field.formatter.settings.media_remote_buzzsprout: type: mapping label: 'Buzzsprout display format settings' Loading media_remote.module +5 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,11 @@ function media_remote_theme($existing, $type, $theme, $path) { 'height' => NULL, ], ], 'media_remote_brightcove' => [ 'variables' => [ 'url' => NULL, ], ], 'media_remote_buzzsprout' => [ 'variables' => [ 'episode_id' => NULL, Loading src/Plugin/Field/FieldFormatter/MediaRemoteBrightcoveFormatter.php 0 → 100644 +73 −0 Original line number Diff line number Diff line <?php namespace Drupal\media_remote\Plugin\Field\FieldFormatter; use Drupal\Core\Field\FieldItemListInterface; /** * Plugin implementation of the 'media_remote_brightcove' formatter. * * @FieldFormatter( * id = "media_remote_brightcove", * label = @Translation("Remote Media - Brightcove"), * field_types = { * "string" * } * ) */ class MediaRemoteBrightcoveFormatter extends MediaRemoteFormatterBase { /** * {@inheritdoc} */ public static function getUrlRegexPattern() { return '/^https:\/\/players\.brightcove\.net\/([\d]+)\/default_default\/index\.html\?videoId=([\d]+)/'; } /** * {@inheritdoc} */ public static function getValidUrlExampleStrings(): array { return [ 'https://players.brightcove.net/[account-id]/default_default/index.html?videoId=[video-id]', ]; } /** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode) { $elements = []; foreach ($items as $delta => $item) { /** @var \Drupal\Core\Field\FieldItemInterface $item */ if ($item->isEmpty()) { continue; } $matches = []; $pattern = static::getUrlRegexPattern(); preg_match_all($pattern, $item->value, $matches); if (empty($matches[1][0])) { continue; } $elements[$delta] = [ '#theme' => 'media_remote_brightcove', '#url' => $item->value, ]; } return $elements; } /** * {@inheritdoc} */ public static function deriveMediaDefaultNameFromUrl($url) { $pattern = static::getUrlRegexPattern(); if (preg_match($pattern, $url)) { return t('Brightcove video @url', [ '@url' => $url, ]); } return parent::deriveMediaDefaultNameFromUrl($url); } } templates/media-remote-brightcove.html.twig 0 → 100644 +18 −0 Original line number Diff line number Diff line {# /** * @file * Template implementation for the media_remote_brightcove theme hook. * * Available variables: * - url: (string) The full URL of the remote video. */ #} <div style="position: relative; display: block; max-width: 960px;"> <div style="padding-top: 56.25%;"> <iframe src="{{ url }}" allowfullscreen="" allow="encrypted-media" style="position: absolute; top: 0; right: 0; bottom: 0; left: 0; width: 100%; height: 100%;"></iframe> </div> </div> Loading
README.md +1 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ Supported providers / Formatters included: - Apple Podcasts - Box - Brightcove - Buzzsprout - Dacast - Deezer Loading
config/schema/media_remote.schema.yml +8 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,14 @@ field.formatter.settings.media_remote_box: type: string label: 'Iframe height' field.formatter.settings.media_remote_brightcove: type: mapping label: 'Brightcove display format settings' mapping: formatter_class: type: string label: 'Formatter class name' field.formatter.settings.media_remote_buzzsprout: type: mapping label: 'Buzzsprout display format settings' Loading
media_remote.module +5 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,11 @@ function media_remote_theme($existing, $type, $theme, $path) { 'height' => NULL, ], ], 'media_remote_brightcove' => [ 'variables' => [ 'url' => NULL, ], ], 'media_remote_buzzsprout' => [ 'variables' => [ 'episode_id' => NULL, Loading
src/Plugin/Field/FieldFormatter/MediaRemoteBrightcoveFormatter.php 0 → 100644 +73 −0 Original line number Diff line number Diff line <?php namespace Drupal\media_remote\Plugin\Field\FieldFormatter; use Drupal\Core\Field\FieldItemListInterface; /** * Plugin implementation of the 'media_remote_brightcove' formatter. * * @FieldFormatter( * id = "media_remote_brightcove", * label = @Translation("Remote Media - Brightcove"), * field_types = { * "string" * } * ) */ class MediaRemoteBrightcoveFormatter extends MediaRemoteFormatterBase { /** * {@inheritdoc} */ public static function getUrlRegexPattern() { return '/^https:\/\/players\.brightcove\.net\/([\d]+)\/default_default\/index\.html\?videoId=([\d]+)/'; } /** * {@inheritdoc} */ public static function getValidUrlExampleStrings(): array { return [ 'https://players.brightcove.net/[account-id]/default_default/index.html?videoId=[video-id]', ]; } /** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode) { $elements = []; foreach ($items as $delta => $item) { /** @var \Drupal\Core\Field\FieldItemInterface $item */ if ($item->isEmpty()) { continue; } $matches = []; $pattern = static::getUrlRegexPattern(); preg_match_all($pattern, $item->value, $matches); if (empty($matches[1][0])) { continue; } $elements[$delta] = [ '#theme' => 'media_remote_brightcove', '#url' => $item->value, ]; } return $elements; } /** * {@inheritdoc} */ public static function deriveMediaDefaultNameFromUrl($url) { $pattern = static::getUrlRegexPattern(); if (preg_match($pattern, $url)) { return t('Brightcove video @url', [ '@url' => $url, ]); } return parent::deriveMediaDefaultNameFromUrl($url); } }
templates/media-remote-brightcove.html.twig 0 → 100644 +18 −0 Original line number Diff line number Diff line {# /** * @file * Template implementation for the media_remote_brightcove theme hook. * * Available variables: * - url: (string) The full URL of the remote video. */ #} <div style="position: relative; display: block; max-width: 960px;"> <div style="padding-top: 56.25%;"> <iframe src="{{ url }}" allowfullscreen="" allow="encrypted-media" style="position: absolute; top: 0; right: 0; bottom: 0; left: 0; width: 100%; height: 100%;"></iframe> </div> </div>