You are here

function dropzonejs_requirements in DropzoneJS 8.2

Same name and namespace in other branches
  1. 8 dropzonejs.install \dropzonejs_requirements()

Implements hook_requirements().

File

./dropzonejs.install, line 11
Install, update and uninstall functions for the dropzonejs module.

Code

function dropzonejs_requirements($phase) {
  $requirements = [];

  // @todo Remove this conditional structure in favor of using the libraries
  // directory file finder service when Drupal 8.9 is the minimum supported
  // version of core.
  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');
    $library_found = (bool) $library_file_finder
      ->find('dropzone/dist/min/dropzone.min.js');
  }
  else {
    $path = DRUPAL_ROOT . '/libraries/dropzone/dist/min/dropzone.min.js';
    if (\Drupal::moduleHandler()
      ->moduleExists('libraries')) {
      $path = libraries_get_path('dropzone') . '/dist/min/dropzone.min.js';
    }

    // Is the library found in the root libraries path.
    $library_found = file_exists($path);

    // If library is not found, then look in the current profile libraries path.
    if (!$library_found) {
      $profile_path = drupal_get_path('profile', \Drupal::installProfile());
      $profile_path .= '/libraries/dropzone/dist/min/dropzone.min.js';

      // Is the library found in the current profile libraries path.
      $library_found = file_exists($profile_path);
    }
  }
  if (!$library_found) {
    $requirements['dropzonejs_library'] = [
      'title' => t('Dropzone library missing'),
      'description' => t('Dropzonejs requires the dropzone.min.js library.
        Download it (https://github.com/enyo/dropzone) and place it in the
        libraries folder (/libraries)'),
      'severity' => REQUIREMENT_ERROR,
    ];
  }
  return $requirements;
}