function environment_indicator_get_active in Environment Indicator 7.2
Same name and namespace in other branches
- 8.2 environment_indicator.module \environment_indicator_get_active()
Helper function to get the active indicator.
Return value
array The active environment array.
5 calls to environment_indicator_get_active()
- EnvironmentVariableRealmController::getRequestKey in environment_indicator_variable/
class/ EnvironmentVariableRealmController.php - Implementation of VariableRealmControllerInterface::getRequestKey().
- environment_indicator_admin_menu_output_alter in ./
environment_indicator.module - Implements hook_admin_menu_output_alter().
- environment_indicator_navbar in ./
environment_indicator.module - Implements hook_navbar().
- environment_indicator_page_build in ./
environment_indicator.module - Implements hook_page_build().
- _environment_indicator_switcher_menu in ./
environment_indicator.module - Helper function to generate a menu with the environments to switch to.
File
- ./
environment_indicator.module, line 404 - Module implementation file.
Code
function environment_indicator_get_active() {
global $base_path;
$env =& drupal_static(__FUNCTION__);
// 1. Check the static cache.
if (isset($env)) {
return $env;
}
// 2. Check if the indicator is in settings.php.
if (_environment_indicator_is_overwritten()) {
$env = environment_indicator_alter_and_cache(_environment_indicator_load_overwritten());
return $env;
}
// 3. Check if the indicator is in the db cache.
if ($cached_env = cache_get('environment_indicator')) {
return $cached_env->data;
}
// 4. Load all the environments and match them to the current environment.
$environments = environment_indicator_get_all();
$matches = array();
foreach ($environments as $machine => $environment) {
// Check if the environment record has been disabled.
// Then check the regex.
if (preg_match("@{$environment->regexurl}@", $_SERVER['HTTP_HOST'] . $base_path)) {
$settings = $environment->settings;
$matches[] = array(
'name' => $environment->name,
'machine' => $environment->machine,
'weight' => $settings['weight'],
'color' => $settings['color'],
'text_color' => $settings['text_color'],
'position' => $settings['position'],
'fixed' => $settings['fixed'],
);
}
}
uasort($matches, 'drupal_sort_weight');
// Return the first match.
if ($env = reset($matches)) {
$env = environment_indicator_alter_and_cache($env);
return $env;
}
return NULL;
}