You are here

function template_preprocess_media_soundcloud_embed in Media entity Soundcloud 8.2

Same name and namespace in other branches
  1. 8 media_entity_soundcloud.theme.inc \template_preprocess_media_soundcloud_embed()
  2. 3.x media_entity_soundcloud.theme.inc \template_preprocess_media_soundcloud_embed()

Prepares variables for media_entity_soundcloud templates.

Default template: media-soundcloud-embed.html.twig.

File

./media_entity_soundcloud.theme.inc, line 15
Theme functions for the media_entity_soundcloud module.

Code

function template_preprocess_media_soundcloud_embed(&$variables) {

  // Build the embed url.
  $uri = 'https://w.soundcloud.com/player/';

  // Build the query.
  $query = [
    'url' => 'https://api.soundcloud.com/' . $variables['source_id'],
  ];

  // Add visual.
  $query['visual'] = $variables['type'] == 'visual';

  // Add options.
  foreach ($variables['options'] as $option => $value) {
    $query[$option] = $value == '0' ? 'false' : 'true';
  }
  $url = Url::fromUri($uri, [
    'query' => $query,
  ]);
  $variables['url'] = $url
    ->toString();
}