You are here

function file_browser_requirements in File Entity Browser 8

Implements hook_requirements().

File

./file_browser.install, line 44
Defines library requirements and install routines for File Browser.

Code

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

  // Optionally use the Libraries module to determine our library paths.
  if (\Drupal::moduleHandler()
    ->moduleExists('libraries')) {
    $imagesloaded_path = libraries_get_path('imagesloaded') . '/imagesloaded.pkgd.min.js';
    $masonry_path = libraries_get_path('masonry') . '/dist/masonry.pkgd.min.js';
  }
  else {
    $imagesloaded_path = DRUPAL_ROOT . '/libraries/imagesloaded/imagesloaded.pkgd.min.js';
    $masonry_path = DRUPAL_ROOT . '/libraries/masonry/dist/masonry.pkgd.min.js';
  }
  if (!file_exists($imagesloaded_path)) {
    $requirements['imagesloaded'] = [
      'title' => t('imagesLoaded library missing'),
      'description' => t('File Browser requires the imagesLoaded library. Download the newest release
from https://github.com/desandro/imagesloaded releases and place it in /libraries'),
      'severity' => REQUIREMENT_ERROR,
    ];
  }
  if (!file_exists($masonry_path)) {
    $requirements['masonry'] = [
      'title' => t('Masonry library missing'),
      'description' => t('File Browser requires the Masonry library. Download the newest release from
https://github.com/desandro/masonry/releases and place it in /libraries'),
      'severity' => REQUIREMENT_ERROR,
    ];
  }

  // Prevent installation if the webserver cannot write to "public://" .
  $public_path = \Drupal::service('file_system')
    ->realpath('public://');
  if ($public_path !== FALSE && !\Drupal::isConfigSyncing() && !is_writable($public_path)) {
    $requirements['public_files_not_writable'] = [
      'title' => t('Public files directory not writable'),
      'description' => t('The webserver needs to be able to write to the public files directory (public://). Please check your server configuration and try again.'),
      'severity' => REQUIREMENT_ERROR,
    ];
  }
  return $requirements;
}