Loading README.md +1 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ Supported providers / Formatters included: - DocumentCloud - Dropbox - Google Drive docs (Documents, Spreadsheets and Slides) - Libsyn - NPR videos - Quickbase - ... Loading config/schema/media_remote.schema.yml +8 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,14 @@ field.formatter.settings.media_remote_google: type: string label: 'Iframe height' field.formatter.settings.media_remote_libsyn: type: mapping label: 'Libsyn display format settings' mapping: formatter_class: type: string label: 'Formatter class name' field.formatter.settings.media_remote_npr: type: mapping label: 'NPR display format settings' Loading media_remote.module +5 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,11 @@ function media_remote_theme($existing, $type, $theme, $path) { 'height' => NULL, ], ], 'media_remote_libsyn' => [ 'variables' => [ 'episode_id' => NULL, ], ], 'media_remote_npr' => [ 'variables' => [ 'url' => NULL, Loading src/Plugin/Field/FieldFormatter/MediaRemoteLibsynFormatter.php 0 → 100644 +74 −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_libsyn' formatter. * * @FieldFormatter( * id = "media_remote_libsyn", * label = @Translation("Remote Media - Libsyn"), * field_types = { * "string" * } * ) */ class MediaRemoteLibsynFormatter extends MediaRemoteFormatterBase { /** * {@inheritdoc} */ public static function getUrlRegexPattern() { return '/^https:\/\/directory\.libsyn\.com\/episode\/index\/id\/([\d]+)/'; } /** * {@inheritdoc} */ public static function getValidUrlExampleStrings(): array { return [ 'https://directory.libsyn.com/episode/index/id/20026970', ]; } /** * {@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; } $episode_id = $matches[1][0]; $elements[$delta] = [ '#theme' => 'media_remote_libsyn', '#episode_id' => $episode_id, ]; } return $elements; } /** * {@inheritdoc} */ public static function deriveMediaDefaultNameFromUrl($url) { $pattern = static::getUrlRegexPattern(); if (preg_match($pattern, $url)) { return t('Libsyn episode from @url', [ '@url' => $url, ]); } return parent::deriveMediaDefaultNameFromUrl($url); } } templates/media-remote-libsyn.html.twig 0 → 100644 +20 −0 Original line number Diff line number Diff line {# /** * @file * Template implementation for the media_remote_libsyn theme hook. * * Available variables: * - episode_id: (string) The episode ID. */ #} <iframe title="Embed Player" style="border: medium none;" scrolling="no" src="//play.libsyn.com/embed/episode/id/{{ episode_id }}/height/200/theme/modern/size/large/thumbnail/yes/custom-color/87A93A/download/no" allowfullscreen="" webkitallowfullscreen="true" mozallowfullscreen="true" oallowfullscreen="true" msallowfullscreen="true" width="100%" height="200"></iframe> Loading
README.md +1 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ Supported providers / Formatters included: - DocumentCloud - Dropbox - Google Drive docs (Documents, Spreadsheets and Slides) - Libsyn - NPR videos - Quickbase - ... Loading
config/schema/media_remote.schema.yml +8 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,14 @@ field.formatter.settings.media_remote_google: type: string label: 'Iframe height' field.formatter.settings.media_remote_libsyn: type: mapping label: 'Libsyn display format settings' mapping: formatter_class: type: string label: 'Formatter class name' field.formatter.settings.media_remote_npr: type: mapping label: 'NPR display format settings' Loading
media_remote.module +5 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,11 @@ function media_remote_theme($existing, $type, $theme, $path) { 'height' => NULL, ], ], 'media_remote_libsyn' => [ 'variables' => [ 'episode_id' => NULL, ], ], 'media_remote_npr' => [ 'variables' => [ 'url' => NULL, Loading
src/Plugin/Field/FieldFormatter/MediaRemoteLibsynFormatter.php 0 → 100644 +74 −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_libsyn' formatter. * * @FieldFormatter( * id = "media_remote_libsyn", * label = @Translation("Remote Media - Libsyn"), * field_types = { * "string" * } * ) */ class MediaRemoteLibsynFormatter extends MediaRemoteFormatterBase { /** * {@inheritdoc} */ public static function getUrlRegexPattern() { return '/^https:\/\/directory\.libsyn\.com\/episode\/index\/id\/([\d]+)/'; } /** * {@inheritdoc} */ public static function getValidUrlExampleStrings(): array { return [ 'https://directory.libsyn.com/episode/index/id/20026970', ]; } /** * {@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; } $episode_id = $matches[1][0]; $elements[$delta] = [ '#theme' => 'media_remote_libsyn', '#episode_id' => $episode_id, ]; } return $elements; } /** * {@inheritdoc} */ public static function deriveMediaDefaultNameFromUrl($url) { $pattern = static::getUrlRegexPattern(); if (preg_match($pattern, $url)) { return t('Libsyn episode from @url', [ '@url' => $url, ]); } return parent::deriveMediaDefaultNameFromUrl($url); } }
templates/media-remote-libsyn.html.twig 0 → 100644 +20 −0 Original line number Diff line number Diff line {# /** * @file * Template implementation for the media_remote_libsyn theme hook. * * Available variables: * - episode_id: (string) The episode ID. */ #} <iframe title="Embed Player" style="border: medium none;" scrolling="no" src="//play.libsyn.com/embed/episode/id/{{ episode_id }}/height/200/theme/modern/size/large/thumbnail/yes/custom-color/87A93A/download/no" allowfullscreen="" webkitallowfullscreen="true" mozallowfullscreen="true" oallowfullscreen="true" msallowfullscreen="true" width="100%" height="200"></iframe>