You are here

environment.install in Environment 8

Same filename and directory in other branches
  1. 6 environment.install
  2. 7 environment.install

Handles installation of the Environment module.

File

environment.install
View source
<?php

/**
 * @file
 * Handles installation of the Environment module.
 */
use Drupal\Core\Url;

/**
 * Implements hook_install().
 */
function environment_install() {

  // New module weights in core: put environment as the very last in the chain.

  //db_query("UPDATE {system} SET weight = -100 WHERE name = 'environment'");
}

/**
 * Implements hook_uninstall().
 */
function environment_uninstall() {
  \Drupal::config('environment.settings')
    ->clear('environment_override')
    ->save();
  \Drupal::config('environment.settings')
    ->clear('environment_require_override')
    ->save();
}

/**
 * Implements hook_requirements().
 */
function environment_requirements($phase) {
  $requirements = array();
  if ($phase == 'runtime') {
    $t = 't';
    $env_req_override = \Drupal::config('environment.settings')
      ->get('environment_require_override');
    $env_current = environment_current(TRUE);
    if ($env_req_override) {
      $env_override = \Drupal::config('environment.settings')
        ->get('environment_override');
      if (empty($env_override)) {
        $requirements['environment_require_override'] = array(
          'title' => $t('Environment Override'),
          'description' => $t("You should override the 'environment_override' variable in your settings.php file to indicate the server environment this site is in."),
          'value' => $t('Missing'),
          'severity' => REQUIREMENT_ERROR,
        );
      }
      else {
        $requirements['environment_require_override'] = array(
          'title' => $t('Environment Override'),
          'description' => $t("The 'environment_override' variable is properly set in settings.php or elsewhere."),
          'value' => $t('Exists'),
          'severity' => REQUIREMENT_OK,
        );
      }
    }
    if (empty($env_current)) {
      $requirements['environment'] = array(
        'title' => $t('Environment'),
        'description' => $t('The environment is not set in your system.'),
        'value' => $t('Invalid State'),
        'severity' => REQUIREMENT_WARNING,
      );
    }
    else {
      $requirements['environment_' . $key] = array(
        'title' => $t('Environment'),
        'description' => $env_current
          ->get('id'),
        'value' => $env_current
          ->get('label'),
        'severity' => REQUIREMENT_INFO,
      );
    }
  }
  return $requirements;
}