You are here

function salvattore_requirements in Salvattore (CSS driven Masonry) 8

Same name and namespace in other branches
  1. 7.2 salvattore.install \salvattore_requirements()

Implements hook_requirements().

Changes its status based on ability to locate JS library. Changes its instructions based on Libraries API being enabled.

File

./salvattore.install, line 30
Salvattore module install file.

Code

function salvattore_requirements($phase) {
  $requirements = array();
  switch ($phase) {
    case 'runtime':

      /*
       * Test for conditions
       */

      // Test if Libraries module is being used.
      if (\Drupal::moduleHandler()
        ->moduleExists('libraries')) {
        $path = libraries_get_path('salvattore');
        $using_libraries = TRUE;
        $version = salvattore_get_version();
      }
      else {
        $using_libraries = FALSE;
      }

      /*
       * Generate status message and severity
       */

      // Salvattore / Libraries API installed and working correctly.
      // Do the Drupal happy dance!
      if ($path && $using_libraries) {
        $description = FALSE;
        $severity = REQUIREMENT_OK;
      }
      elseif ($path && !$using_libraries) {
        $description = t('Salvattore JS library is installed but you aren\'t using !libraries-api. You should use it.', array(
          '!libraries-api' => \Drupal::l(t('Libraries API'), \Drupal\Core\Url::fromUri('http://drupal.org/project/libraries')),
        ));
        $severity = REQUIREMENT_WARNING;
      }
      elseif (!$path && \Drupal::moduleHandler()
        ->moduleExists('libraries')) {
        $description = t('Salvattore JS library cannot be found. Download it from !salvattore-site, copy it into !path and rename it to salvattore.min.js.', array(
          '!salvattore-site' => \Drupal::l(t('salvattore.com'), \Drupal\Core\Url::fromUri('http://salvattore.com/')),
          // !path has a hardcoded default because the libraries_get_path() function might not return
          // the correct path when conditions lead to this block of code being executed
          '!path' => 'sites/all/libraries/salvattore/dist',
        ));
        $severity = REQUIREMENT_ERROR;
      }
      else {
        $description = t('Salvattore and Libraries API cannot be found. Download Salvattore from !salvattore-site, copy it into !path and rename it to salvattore.min.js. You should also use the !libraries-api by installing from drupal.org.', array(
          '!salvattore-site' => \Drupal::l(t('salvattore.com'), \Drupal\Core\Url::fromUri('http://salvattore.com/download/')),
          '!path' => 'sites/all/libraries/salvattore/dist',
          '!libraries-api' => \Drupal::l(t('Libraries API'), \Drupal\Core\Url::fromUri('http://drupal.org/project/libraries')),
        ));
        $severity = REQUIREMENT_ERROR;
      }

      /*
       * Declare requirement to Drupal
       */
      $requirements[] = array(
        'title' => t('Salvattore'),
        'value' => $version ? $version : t('Not installed'),
        'description' => $description,
        'severity' => $severity,
      );
      break;
  }
  return $requirements;
}