You are here

function template_preprocess_media_soundcloud_embed in Media entity Soundcloud 8

Same name and namespace in other branches
  1. 8.2 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 14
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/?url=https%3A//api.soundcloud.com/tracks/' . $variables['track_id'];

  // Build the query.
  $query = [];

  // 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();
}