Skip to content
Snippets Groups Projects
Commit 72ed069a authored by Marcos Cano's avatar Marcos Cano :speech_balloon: Committed by Marcos Cano
Browse files

Issue #3301812 by Chris Matthews, marcoscano: Add support for Deezer

parent a0a9e824
Branches
Tags 8.x-2.0-alpha4
No related merge requests found
......@@ -25,6 +25,7 @@ Supported providers / Formatters included:
- Box
- Buzzsprout
- Dacast
- Deezer
- DocumentCloud
- Dropbox
- Google Drive docs (Documents, Spreadsheets and Slides)
......
......@@ -38,6 +38,14 @@ field.formatter.settings.media_remote_dacast:
type: string
label: 'Iframe height'
field.formatter.settings.media_remote_deezer:
type: mapping
label: 'Deezer display format settings'
mapping:
formatter_class:
type: string
label: 'Formatter class name'
field.formatter.settings.media_remote_documentcloud:
type: mapping
label: 'Documentcloud display format settings'
......
......@@ -57,6 +57,11 @@ function media_remote_theme($existing, $type, $theme, $path) {
'height' => NULL,
],
],
'media_remote_deezer' => [
'variables' => [
'episode_id' => NULL,
],
],
'media_remote_documentcloud' => [
'variables' => [
'document_id' => NULL,
......
<?php
namespace Drupal\media_remote\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
/**
* Plugin implementation of the 'media_remote_deezer' formatter.
*
* @FieldFormatter(
* id = "media_remote_deezer",
* label = @Translation("Remote Media - Deezer"),
* field_types = {
* "string"
* }
* )
*/
class MediaRemoteDeezerFormatter extends MediaRemoteFormatterBase {
/**
* {@inheritdoc}
*/
public static function getUrlRegexPattern() {
return '/^https:\/\/www\.deezer\.com\/us\/episode\/([\d]+)/';
}
/**
* {@inheritdoc}
*/
public static function getValidUrlExampleStrings(): array {
return [
'https://www.deezer.com/us/episode/419142123',
];
}
/**
* {@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_deezer',
'#episode_id' => $episode_id,
];
}
return $elements;
}
/**
* {@inheritdoc}
*/
public static function deriveMediaDefaultNameFromUrl($url) {
$pattern = static::getUrlRegexPattern();
if (preg_match($pattern, $url)) {
return t('Deezer episode from @url', [
'@url' => $url,
]);
}
return parent::deriveMediaDefaultNameFromUrl($url);
}
}
{#
/**
* @file
* Template implementation for the media_remote_deezer theme hook.
*
* Available variables:
* - episode_id: (string) The episode ID.
*/
#}
<iframe title="deezer-widget"
src="https://widget.deezer.com/widget/auto/episode/{{ episode_id }}?tracklist=false"
width="100%"
height="300"
frameborder="0"
allowtransparency="true"
allow="encrypted-media; clipboard-write"></iframe>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment