You are here

salvattore.install in Salvattore (CSS driven Masonry) 8

Same filename and directory in other branches
  1. 7.2 salvattore.install
  2. 7 salvattore.install

Salvattore module install file.

File

salvattore.install
View source
<?php

/**
 * @file
 * Salvattore module install file.
 */

/**
 * Implements hook_install().
 */
function salvattore_install() {
  \Drupal::configFactory()
    ->getEditable('salvattore.settings')
    ->set('salvattore_use_min_js', '1')
    ->save();
  \Drupal::configFactory()
    ->getEditable('salvattore.settings')
    ->set('salvattore_load_default_css', '0')
    ->save();
}

/**
 * Implements hook_uninstall().
 */
function salvattore_uninstall() {
  \Drupal::config('salvattore.settings')
    ->clear('salvattore_use_min_js')
    ->save();
  \Drupal::config('salvattore.settings')
    ->clear('salvattore_load_default_css')
    ->save();
}

/**
 * Implements hook_requirements().
 *
 * Changes its status based on ability to locate JS library.
 * Changes its instructions based on Libraries API being enabled.
 */
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;
}

Functions