You are here

function tacjs_requirements in TacJS 8

Same name and namespace in other branches
  1. 8.2 tacjs.install \tacjs_requirements()

Implements hook_requirements().

File

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

Code

function tacjs_requirements($phase) {
  $requirements = [];
  $path = DRUPAL_ROOT . '/libraries/tarteaucitron/tarteaucitron.js';
  $path_service = DRUPAL_ROOT . '/libraries/tarteaucitron/tarteaucitron.services.js';
  if (\Drupal::moduleHandler()
    ->moduleExists('libraries')) {
    $path = libraries_get_path('tarteaucitron') . '/tarteaucitron/tarteaucitron.js';
    $path_service = libraries_get_path('tarteaucitron') . '/tarteaucitron/tarteaucitron.services.js';
  }

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

  // If library is not found, then look in the current profile libraries path.
  if (!$library_found && !$library_found_s) {
    $profile_path = drupal_get_path('profile', drupal_get_profile());
    $profile_path .= '/libraries/tarteaucitron/tarteaucitron.js';

    // Is the library found in the current profile libraries path.
    $library_found = file_exists($profile_path);
  }
  if (!$library_found && !$library_found_s) {
    $requirements['tacjs_library'] = [
      'title' => t('Tac js  library missing'),
      'description' => t('Tacjs requires the tarteaucitron library.
        Download it (https://github.com/AmauriC/tarteaucitron.js/), rename directory to tarteaucitron and place it in the
        libraries folder (/libraries)'),
      'severity' => REQUIREMENT_ERROR,
    ];
  }
  return $requirements;
}