You are here

public function AudioFieldFieldFormatter::settingsSummary in AudioField 8

Returns a short summary for the current formatter settings.

If an empty result is returned, a UI can still be provided to display a settings form in case the formatter has configurable settings.

Return value

string[] A short summary of the formatter settings.

Overrides FormatterBase::settingsSummary

File

src/Plugin/Field/FieldFormatter/AudioFieldFieldFormatter.php, line 419

Class

AudioFieldFieldFormatter
Plugin implementation of audio player file formatter.

Namespace

Drupal\audiofield\Plugin\Field\FieldFormatter

Code

public function settingsSummary() {
  $plugin_definitions = $this->audioPlayerManager
    ->getDefinitions();
  $settings = $this
    ->getSettings();

  // Show which player we are currently using for the field.
  $summary = [
    $this
      ->t('Selected player: <strong>@player</strong>', [
      '@player' => $plugin_definitions[$settings['audio_player']]['title'],
    ]),
  ];

  // If this is jPlayer, add those settings.
  if ($settings['audio_player'] == 'jplayer_audio_player') {

    // Display theme.
    $theme = 'None (for styling manually with CSS)';

    // If this is the custom jplayer circle theme.
    if ($settings['audio_player_jplayer_theme'] == 'audiofield.jplayer.theme_jplayer_circle') {
      $theme = 'jPlayer circle player';
    }
    else {
      foreach (_audiofield_list_skins('jplayer_audio_player') as $skin) {
        if ($skin['library_name'] == $settings['audio_player_jplayer_theme']) {
          $theme = $skin['name'];
        }
      }
    }
    $summary[] = $this
      ->t('Skin: <strong>@theme</strong>', [
      '@theme' => $theme,
    ]);
  }
  elseif ($settings['audio_player'] == 'wavesurfer_audio_player') {
    $summary[] = $this
      ->t('Combine files into single player? <strong>@combine</strong>', [
      '@combine' => $settings['audio_player_wavesurfer_combine_files'] ? 'Yes' : 'No',
    ]);
    $summary[] = $this
      ->t('Audio Rate: <strong>@value</strong>', [
      '@value' => $settings['audio_player_wavesurfer_audiorate'],
    ]);
    $summary[] = $this
      ->t('Auto Center? <strong>@value</strong>', [
      '@value' => $settings['audio_player_wavesurfer_autocenter'] ? 'Yes' : 'No',
    ]);
    $summary[] = $this
      ->t('Autoplay next track? <strong>@value</strong>', [
      '@value' => $settings['audio_player_wavesurfer_playnexttrack'] ? 'Yes' : 'No',
    ]);
    $summary[] = $this
      ->t('Bar Gap: <strong>@value</strong>', [
      '@value' => $settings['audio_player_wavesurfer_bargap'],
    ]);
    $summary[] = $this
      ->t('Bar Height: <strong>@value</strong>', [
      '@value' => $settings['audio_player_wavesurfer_barheight'],
    ]);
    $summary[] = $this
      ->t('Bar Width: <strong>@value</strong>', [
      '@value' => $settings['audio_player_wavesurfer_barwidth'],
    ]);
    $summary[] = $this
      ->t('Cursor Color: <span style="border:1px solid black;height:10px;width:10px;display:inline-block;background:@value;"></span>', [
      '@value' => $settings['audio_player_wavesurfer_cursorcolor'],
    ]);
    $summary[] = $this
      ->t('Cursor Width: <strong>@value</strong>', [
      '@value' => $settings['audio_player_wavesurfer_cursorwidth'],
    ]);
    $summary[] = $this
      ->t('Force Decode? <strong>@value</strong>', [
      '@value' => $settings['audio_player_wavesurfer_forcedecode'] ? 'Yes' : 'No',
    ]);
    $summary[] = $this
      ->t('Normalize? <strong>@value</strong>', [
      '@value' => $settings['audio_player_wavesurfer_normalize'] ? 'Yes' : 'No',
    ]);
    $summary[] = $this
      ->t('Progress Color: <span style="border:1px solid black;height:10px;width:10px;display:inline-block;background:@value;"></span>', [
      '@value' => $settings['audio_player_wavesurfer_progresscolor'],
    ]);
    $summary[] = $this
      ->t('Responsive? <strong>@value</strong>', [
      '@value' => $settings['audio_player_wavesurfer_responsive'] ? 'Yes' : 'No',
    ]);
    $summary[] = $this
      ->t('Wave Color: <span style="border:1px solid black;height:10px;width:10px;display:inline-block;background:@value;"></span>', [
      '@value' => $settings['audio_player_wavesurfer_wavecolor'],
    ]);
    $summary[] = $this
      ->t('Use Peak File? <strong>@value</strong>', [
      '@value' => $settings['audio_player_wavesurfer_use_peakfile'] ? 'Yes' : 'No',
    ]);
  }
  elseif ($settings['audio_player'] == 'wordpress_audio_player') {
    $summary[] = $this
      ->t('Combine files into single player? <strong>@combine</strong>', [
      '@combine' => $settings['audio_player_wordpress_combine_files'] ? 'Yes' : 'No',
    ]);
    $summary[] = $this
      ->t('Animate player? <strong>@animate</strong>', [
      '@animate' => $settings['audio_player_wordpress_animation'] ? 'Yes' : 'No',
    ]);
  }
  elseif ($settings['audio_player'] == 'soundmanager_audio_player') {
    $skins = [
      'default' => 'Default theme',
      'player360' => '360 degree player',
      'barui' => 'Bar UI',
      'inlineplayer' => 'Inline Player',
    ];
    $summary[] = $this
      ->t('Skin: <strong>@skin</strong>', [
      '@skin' => $skins[$settings['audio_player_soundmanager_theme']],
    ]);
  }

  // Show combined settings for multiple players.
  if (in_array($settings['audio_player'], [
    'jplayer_audio_player',
    'mediaelement_audio_player',
    'projekktor_audio_player',
    'soundmanager_audio_player',
    'wavesurfer_audio_player',
    'wordpress_audio_player',
  ])) {

    // Display volume.
    $summary[] = $this
      ->t('Initial volume: <strong>@volume out of 10</strong>', [
      '@volume' => $settings['audio_player_initial_volume'],
    ]);
  }

  // Display autoplay.
  if (in_array($settings['audio_player'], [
    'audiojs_audio_player',
    'default_mp3_player',
    'jplayer_audio_player',
    'mediaelement_audio_player',
    'projekktor_audio_player',
    'wavesurfer_audio_player',
    'wordpress_audio_player',
  ])) {
    $summary[] = $this
      ->t('Autoplay: <strong>@autoplay</strong>', [
      '@autoplay' => $settings['audio_player_autoplay'] ? 'Yes' : 'No',
    ]);
  }

  // Display lazy load.
  if (in_array($settings['audio_player'], [
    'audiojs_audio_player',
    'default_mp3_player',
    'jplayer_audio_player',
    'mediaelement_audio_player',
    'projekktor_audio_player',
  ])) {
    $summary[] = $this
      ->t('Lazy Load: <strong>@lazyload</strong>', [
      '@lazyload' => $settings['audio_player_lazyload'] ? 'Yes' : 'No',
    ]);
  }

  // Check to make sure the library is installed.
  $player = $this->audioPlayerManager
    ->createInstance($settings['audio_player']);
  if (!$player
    ->checkInstalled()) {
    $summary[] = $this
      ->t('<strong style="color:red;">Error: this player library is currently not installed. Please select another player or reinstall the library.</strong>');
  }

  // Show whether or not we are displaying download buttons.
  $summary[] = $this
    ->t('Display download button: <strong>@display_link</strong>', [
    '@display_link' => $settings['download_button'] ? 'Yes' : 'No',
  ]);

  // Show whether or not we are displaying direct downloads.
  $summary[] = $this
    ->t('Display download link: <strong>@display_link</strong>', [
    '@display_link' => $settings['download_link'] ? 'Yes' : 'No',
  ]);
  return $summary;
}