class WordPressAudioPlayer in AudioField 8
Implements the WordPress Audio Player plugin.
@AudioPlayer ( id = "wordpress_audio_player", title =
Plugin annotation
@Translation("WordPress audio player"),
  description = @Translation("Standalone audio player originally built for WordPress"),
  fileTypes = {
    "mp3",
  },
  libraryName = "wordpress",
  website = "http://wpaudioplayer.com",
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface- class \Drupal\audiofield\AudioFieldPluginBase implements ContainerFactoryPluginInterface uses StringTranslationTrait- class \Drupal\audiofield\Plugin\AudioPlayer\WordPressAudioPlayer
 
 
- class \Drupal\audiofield\AudioFieldPluginBase implements ContainerFactoryPluginInterface uses StringTranslationTrait
Expanded class hierarchy of WordPressAudioPlayer
File
- src/Plugin/ AudioPlayer/ WordPressAudioPlayer.php, line 22 
Namespace
Drupal\audiofield\Plugin\AudioPlayerView source
class WordPressAudioPlayer extends AudioFieldPluginBase {
  /**
   * {@inheritdoc}
   */
  public function renderPlayer(FieldItemListInterface $items, $langcode, array $settings) {
    // Check to make sure we're installed.
    if (!$this
      ->checkInstalled()) {
      // Show the error.
      $this
        ->showInstallError();
      // Simply return the default rendering so the files are still displayed.
      return $this
        ->renderDefaultPlayer($items, $settings);
    }
    // Start building settings to pass to the javascript WordPress builder.
    $player_settings = [
      // WordPress expects this as a 0 - 100 range.
      'volume' => $settings['audio_player_initial_volume'] * 10,
      'animate' => $settings['audio_player_wordpress_animation'] ? 'yes' : 'no',
      'files' => [],
      'autoplay' => $settings['audio_player_autoplay'],
    ];
    // Format files for output.
    $template_files = $this
      ->getItemRenderList($items, $settings['audio_player_wordpress_combine_files'] ? 1 : 0);
    foreach ($template_files as $renderInfo) {
      // Pass settings for the file.
      $player_settings['files'][] = [
        'file' => $renderInfo->url
          ->toString(),
        'title' => $renderInfo->description,
        'unique_id' => $renderInfo->id,
      ];
    }
    // If we are combining into a single player, make some modifications.
    if ($settings['audio_player_wordpress_combine_files']) {
      // Wordpress expects comma-deliminated lists
      // when using multiple files in a single player.
      $wp_files = [];
      $wp_titles = [];
      foreach ($player_settings['files'] as $wp_file) {
        $wp_files[] = $wp_file['file'];
        $wp_titles[] = $wp_file['title'];
      }
      // Redeclare settings with only a single (combined) file.
      $player_settings['files'] = [
        [
          'file' => implode(',', $wp_files),
          'title' => implode(',', $wp_titles),
          'unique_id' => $player_settings['files'][0]['unique_id'],
        ],
      ];
    }
    return [
      'audioplayer' => [
        '#theme' => 'audioplayer',
        '#plugin_id' => 'wordpress',
        '#settings' => $settings,
        '#files' => $template_files,
      ],
      'downloads' => $this
        ->createDownloadList($items, $settings),
      '#attached' => [
        'library' => [
          // Attach the WordPress library.
          'audiofield/audiofield.' . $this
            ->getPluginLibraryName(),
        ],
        'drupalSettings' => [
          'audiofieldwordpress' => [
            $this
              ->getUniqueRenderId() => $player_settings,
          ],
        ],
      ],
    ];
  }
  /**
   * {@inheritdoc}
   */
  public function getPluginLibraryVersion() {
    // Parse the audio-player.js file for version info.
    $library_path = $this->fileSystem
      ->realpath(DRUPAL_ROOT . $this
      ->getPluginLibraryPath() . '/audio-player.js');
    $library_data = file_get_contents($library_path);
    $matches = [];
    preg_match('%SWFObject v([0-9\\.]+).*%', $library_data, $matches);
    return $matches[1];
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| AudioFieldPluginBase:: | protected | property | File System service. | |
| AudioFieldPluginBase:: | protected | property | Library discovery service. | |
| AudioFieldPluginBase:: | protected | property | Messenger service. | |
| AudioFieldPluginBase:: | protected | property | Messenger service. | |
| AudioFieldPluginBase:: | public | function | Checks to see if this audio plugin has been properly installed. | 1 | 
| AudioFieldPluginBase:: | public | function | Checks to see if this audio plugin version is up to date. | |
| AudioFieldPluginBase:: | public static | function | Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: | 1 | 
| AudioFieldPluginBase:: | public | function | Used to render list of downloads as an item list. | |
| AudioFieldPluginBase:: | private | function | Get a title description from an audiofield entity. | |
| AudioFieldPluginBase:: | public | function | Get required rendering information from an entity. | |
| AudioFieldPluginBase:: | private | function | Get source URL from an audiofield entity. | |
| AudioFieldPluginBase:: | protected | function | Get the class type for an entity. | |
| AudioFieldPluginBase:: | private | function | Get the filetype for an item. | |
| AudioFieldPluginBase:: | public | function | Used to format file entities for use in the twig themes. | |
| AudioFieldPluginBase:: | public | function | Gets the definition of the plugin implementation. Overrides PluginBase:: | |
| AudioFieldPluginBase:: | public | function | Gets the plugin_id of the plugin instance. Overrides PluginBase:: | |
| AudioFieldPluginBase:: | public | function | Gets the main library instance of this plugin. | |
| AudioFieldPluginBase:: | public | function | Gets the name of the main library of the plugin instance. | |
| AudioFieldPluginBase:: | public | function | Gets the location of this plugin's library installation. | |
| AudioFieldPluginBase:: | public | function | Gets the remote download source from the plugin's main library. | |
| AudioFieldPluginBase:: | public | function | Gets the title of the plugin instance. | |
| AudioFieldPluginBase:: | private | function | Get a unique ID for an item. | |
| AudioFieldPluginBase:: | protected | function | Get a unique audofield ID. | |
| AudioFieldPluginBase:: | private | function | Load a file from an audio file entity. | |
| AudioFieldPluginBase:: | public | function | Used to render a default player (for fallback). | |
| AudioFieldPluginBase:: | public | function | Shows library installation errors for in-use libraries. | |
| AudioFieldPluginBase:: | protected | function | Validate that this entity will work with this player. | |
| AudioFieldPluginBase:: | private | function | Validate that a file entity will work with this player. | |
| AudioFieldPluginBase:: | private | function | Validate that a link entity will work with this player. | |
| AudioFieldPluginBase:: | public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: | 1 | 
| PluginBase:: | protected | property | Configuration information passed into the plugin. | 1 | 
| PluginBase:: | protected | property | The plugin implementation definition. | 1 | 
| PluginBase:: | protected | property | The plugin_id. | |
| PluginBase:: | constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
| PluginBase:: | public | function | Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: | |
| PluginBase:: | public | function | Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: | |
| PluginBase:: | public | function | Determines if the plugin is configurable. | |
| StringTranslationTrait:: | protected | property | The string translation service. | 1 | 
| StringTranslationTrait:: | protected | function | Formats a string containing a count of items. | |
| StringTranslationTrait:: | protected | function | Returns the number of plurals supported by a given language. | |
| StringTranslationTrait:: | protected | function | Gets the string translation service. | |
| StringTranslationTrait:: | public | function | Sets the string translation service to use. | 2 | 
| StringTranslationTrait:: | protected | function | Translates a string to the current language or to a given language. | |
| WordPressAudioPlayer:: | public | function | Parses library to get version number of installed library. Overrides AudioFieldPluginBase:: | |
| WordPressAudioPlayer:: | public | function | Renders the player. Overrides AudioFieldPluginBase:: | 
