You are here

function context_condition_map in Context 6

Same name and namespace in other branches
  1. 6.3 context.module \context_condition_map()
  2. 6.2 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().

3 calls to context_condition_map()
context_condition::condition_used in plugins/context_condition.inc
Check whether this condition is used by any contexts. Can be used to prevent expensive condition checks from being triggered when no contexts use this condition.
context_condition::get_contexts in plugins/context_condition.inc
Retrieve all contexts with the condition value provided.
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 457

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;
}