You are here

function hook_environment_switch in Environment 8

Same name and namespace in other branches
  1. 6 environment.api.php \hook_environment_switch()
  2. 7 environment.api.php \hook_environment_switch()

React to an environment state change.

Use this hook to specify changes to your site configuration depending on what kind of environment the site is operating in. For example, production environments should not have developer/site-builder oriented modules enabled, such as administrative UI modules.

When defining your state change actions, be careful to account for a given state always consisting of the same behaviors and configuration, regardless of how it returns to that state (which previous environment it was in.) Be careful that you do not *disable* any modules in one environment that implement a necessary instance of hook_environment_switch().

Parameters

string $target_env: The name of the environment being activated.

string $current_env: The name of the environment being deactivated.

Return value

string String summarizing changes made for drush user.

1 function implements hook_environment_switch()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

drush_environment_switch in ./environment.drush.inc
Implements drush_hook_COMMAND for environment_switch.
1 invocation of hook_environment_switch()
environment_switch in ./environment.module
Switches between two environments.

File

./environment.api.php, line 34
Hooks provided by Environment.

Code

function hook_environment_switch($target_env, $current_env) {

  // Declare each optional development-related module.
  $devel_modules = array(
    'devel',
    'devel_generate',
    'devel_node_access',
  );
  switch ($target_env) {
    case 'production':
      module_disable($devel_modules);
      drupal_set_message('Disabled development modules');
      return;
    case 'development':
      module_enable($devel_modules);
      drupal_set_message('Enabled development modules');
      return;
  }
}