You are here

function jw_player_skins in JW Player 8

Same name and namespace in other branches
  1. 7.2 jw_player.module \jw_player_skins()
  2. 7 jw_player.module \jw_player_skins()

Retrieves information about JW Player skins.

Parameters

string $name: Name of skin for which information will be returned (optional).

Return value

object|array If $name is provided, will return the $file object. Otherwise if $name is NULL, will return an array of $file objects.

1 call to jw_player_skins()
JwplayerPresetAdd::form in src/Form/JwplayerPresetAdd.php
Gets the actual form array to be built.

File

./jw_player.module, line 58
Adds a theme function which allows theme developers to use the JW Player.

Code

function jw_player_skins($name = NULL) {
  $skins =& drupal_static(__FUNCTION__);
  $config = \Drupal::config('jw_player.settings');
  if (!isset($skins)) {
    $skins = [];

    // Get custom JW Player skins stored in 'jwplayer_skins' directory.
    $pattern = jw_player_use_legacy() ? '/\\.xml|\\.swf$/' : '/\\.css$/';
    if (\Drupal::hasService('library.libraries_directory_file_finder')) {

      /** @var \Drupal\Core\Asset\LibrariesDirectoryFileFinder $library_file_finder */
      $library_file_finder = \Drupal::service('library.libraries_directory_file_finder');
      $directory = $library_file_finder
        ->find('jwplayer_skins');
    }
    elseif (\Drupal::moduleHandler()
      ->moduleExists('libraries')) {
      $directory = libraries_get_path('jwplayer_skins');
    }
    else {
      $directory = 'libraries/jwplayer_skins';
    }
    $custom_skins = [];
    if ($directory && !file_exists($directory)) {
      $custom_skins = \Drupal::service('file_system')
        ->scanDirectory($directory, $pattern);
      foreach ($custom_skins as $key => $custom_skin) {
        $custom_skins[$key]->skin_type = 'custom';
      }
    }

    // Get JW Player 7 skins provided with self-hosted version.
    $library_skins = [];
    if (!jw_player_use_legacy() && $config
      ->get('jw_player_key')) {
      if (\Drupal::hasService('library.libraries_directory_file_finder')) {

        /** @var \Drupal\Core\Asset\LibrariesDirectoryFileFinder $library_file_finder */
        $library_file_finder = \Drupal::service('library.libraries_directory_file_finder');
        $directory = $library_file_finder
          ->find('jwplayer');
      }
      elseif (\Drupal::moduleHandler()
        ->moduleExists('libraries')) {
        $directory = libraries_get_path('jwplayer');
      }
      else {
        $directory = 'libraries/jwplayer_skins';
      }
      if ($directory && !file_exists($directory)) {
        $library_skins = \Drupal::service('file_system')
          ->scanDirectory($directory . '/skins', $pattern);
        foreach ($library_skins as $key => $library_skin) {
          $library_skins[$key]->skin_type = 'library';
        }
      }
    }
    $skins = array_merge($library_skins, $custom_skins);
  }
  if ($name) {
    foreach ($skins as $file) {
      if ($file->name == $name) {
        return $file;
      }
    }
  }

  // Sort skin array in alphabetical order.
  asort($skins);
  return $skins;
}