You are here

function context_condition_map in Context 6.2

Same name and namespace in other branches
  1. 6.3 context.module \context_condition_map()
  2. 6 context.module \context_condition_map()
  3. 7.3 context.module \context_condition_map()

Loads an associative array of conditions => context identifiers to allow contexts to be set by different conditions. Called by context_set_by_condition().

2 calls to context_condition_map()
context_context_page_condition in ./context.core.inc
Implementation of hook_context_page_condition().
context_set_by_condition in ./context.module
Sets a namespace-attribute-value context that has been associated with the provided condition.

File

./context.module, line 461

Code

function context_condition_map($reset = FALSE) {
  static $condition_map;
  if (!isset($condition_map) || $reset) {
    $cache = context_cache_get('condition_map');
    if ($cache && !$reset) {
      $condition_map = $cache;
    }
    else {
      $enabled = context_enabled_contexts();
      foreach (array_keys(context_conditions()) as $condition) {
        $condition_map[$condition] = array();
        foreach ($enabled as $identifier => $context) {
          if (!empty($context->{$condition})) {
            if (is_array($context->{$condition})) {
              foreach ($context->{$condition} as $value) {
                if (!isset($condition_map[$condition][$value])) {
                  $condition_map[$condition][$value] = array();
                }
                $condition_map[$condition][$value][] = $identifier;
              }
            }
            else {
              if (is_string($context->{$condition})) {
                $value = $context->{$condition};
                if (!isset($condition_map[$condition][$value])) {
                  $condition_map[$condition][$value] = array();
                }
                $condition_map[$condition][$value][] = $identifier;
              }
            }
          }
        }
      }
      context_cache_set('condition_map', $condition_map);
    }
  }
  return $condition_map;
}