You are here

function jw_player_requirements in JW Player 8

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

Implements hook_requirements().

File

./jw_player.install, line 13
Install, update and uninstall functions for the JW Player module.

Code

function jw_player_requirements($phase) {
  $requirements = array();

  // Check the existence of the JW Player Library.
  if ($phase == 'runtime') {

    // Check whether the library version 7 exists in library folder.
    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';
    }
    $errors = array();
    $config = \Drupal::config('jw_player.settings');
    foreach (array(
      'jwplayer.flash.swf',
      'jwplayer.js',
      'jwplayer.html5.js',
    ) as $file) {

      // JW Player 7 doesn't have jwplayer.html5.js file anymore.
      if ($file == 'jwplayer.html5.js' && $config
        ->get('jw_player_version') != '6') {
        continue;
      }
      if (!$directory || !file_exists($directory . '/' . $file)) {
        $errors[] = t('The file %file is not present in the directory %directory', array(
          '%file' => $file,
          '%directory' => $directory,
        ));
      }
    }
    $requirements['jw_player'] = array(
      'title' => t('JW Player'),
      'value' => !empty($errors) ? [
        '#markup' => \Drupal::theme()
          ->render('item_list', array(
          'items' => $errors,
        )) . t('Please consult INSTALL.txt for installation instructions.'),
      ] : t('Installed correctly'),
      'severity' => !empty($errors) ? REQUIREMENT_ERROR : REQUIREMENT_OK,
    );
  }
  return $requirements;
}