Commit a1b0bd3f authored by Marcos Cano's avatar Marcos Cano 💬 Committed by Marcos Cano
Browse files

Issue #3226845 by marcoscano, Chris Matthews: Add support for Libsyn

parent 618761e4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ Supported providers / Formatters included:
- DocumentCloud
- Dropbox
- Google Drive docs (Documents, Spreadsheets and Slides)
- Libsyn
- NPR videos
- Quickbase
- ...
+8 −0
Original line number Diff line number Diff line
@@ -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'
+5 −0
Original line number Diff line number Diff line
@@ -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,
+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);
  }

}
+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>