You are here

function environment_indicator_get_active in Environment Indicator 8.2

Same name and namespace in other branches
  1. 7.2 environment_indicator.module \environment_indicator_get_active()

Helper function to get the active indicator.

5 calls to environment_indicator_get_active()
environment_indicator_admin_menu_output_alter in ./environment_indicator.module
Implements hook_admin_menu_output_alter().
environment_indicator_page_build in ./environment_indicator.module
Implements hook_page_build().
environment_indicator_toolbar in ./environment_indicator.module
Implements hook_toolbar().
theme_environment_indicator_indicator_name in ./environment_indicator.theme.inc
Theme function for the indicator name.
_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 221
Module implementation file.

Code

function environment_indicator_get_active() {
  $env =& drupal_static(__FUNCTION__);
  if (isset($env)) {
    return $env;
  }
  $environments = environment_indicator_get_all();
  $matches = array();
  foreach ($environments as $machine => $environment) {

    // Check if the environment record has ben disabled. Then check the regex.
    if (environment_indicator_match_path($environment->regexurl)) {
      $matches[] = array(
        'name' => $environment->name,
        'machine' => $environment->machine,
        'weight' => $environment->weight,
        'color' => $environment->color,
        'position' => $environment->position,
        'fixed' => $environment->fixed,
      );
    }
  }
  uasort($matches, array(
    'Drupal\\Component\\Utility\\SortArray',
    'sortByWeightElement',
  ));
  $env = reset($matches);
  return $env;
}