You are here

public function AudioFieldPluginBase::createDownloadList in AudioField 8

Used to render list of downloads as an item list.

Parameters

object $items: A list of items for which we need to generate download links..

array $settings: An array of additional render settings.

Return value

array A render array containing download links.

8 calls to AudioFieldPluginBase::createDownloadList()
AudioFieldPluginBase::renderDefaultPlayer in src/AudioFieldPluginBase.php
Used to render a default player (for fallback).
AudioJsAudioPlayer::renderPlayer in src/Plugin/AudioPlayer/AudioJsAudioPlayer.php
Renders the player.
JPlayerAudioPlayer::renderPlayer in src/Plugin/AudioPlayer/JPlayerAudioPlayer.php
Renders the player.
MediaElementAudioPlayer::renderPlayer in src/Plugin/AudioPlayer/MediaElementAudioPlayer.php
Renders the player.
ProjekktorAudioPlayer::renderPlayer in src/Plugin/AudioPlayer/ProjekktorAudioPlayer.php
Renders the player.

... See full list

File

src/AudioFieldPluginBase.php, line 568

Class

AudioFieldPluginBase
Base class for audiofield plugins. Includes global functions.

Namespace

Drupal\audiofield

Code

public function createDownloadList($items, array $settings) {

  // Check if download links are turned on and there are items.
  if (!$settings['download_link'] || count($items) == 0) {
    return [];
  }
  $links = [];

  // Loop over each item.
  foreach ($items as $item) {
    if ($this
      ->validateEntityAgainstPlayer($item)) {

      // Get the source URL for this item.
      $source_url = $this
        ->getAudioSource($item);

      // Set the download attribute to the filename.
      $source_path = $source_url
        ->getUri();
      $filename = basename($source_path);
      $attributes = $source_url
        ->getOption('attributes');
      $attributes['download'] = urldecode($filename);
      $source_url
        ->setOption('attributes', $attributes);

      // Get the entity description for this item.
      $entity_description = $this
        ->getAudioDescription($item);

      // Add the link.
      $links[] = [
        'link' => Link::fromTextAndUrl($entity_description, $source_url)
          ->toString(),
      ];
    }
  }
  return [
    '#theme' => 'audiofield_download_links',
    '#links' => $links,
  ];
}