You are here

function context_init in Context 6.2

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

Implementation of hook_init().

File

./context.module, line 139

Code

function context_init() {

  // In general it is advisable to avoid using context_set_by_condition() at
  // this stage of the Drupal page load as it caches the condition map.
  $current_path = drupal_get_path_alias($_GET['q']);
  foreach (context_enabled_contexts() as $identifier => $context) {

    // context integration against paths
    if (!empty($context->path) && is_array($context->path)) {
      $paths = implode("\n", $context->path);
      $path_match = drupal_match_path($current_path, $paths);
      if ($current_path != $_GET['q']) {
        $path_match = $path_match || drupal_match_path($_GET['q'], $paths);
      }
      if ($path_match) {
        context_set($context->namespace, $context->attribute, $context->value);
      }
    }

    // context integration for sitewide context
    if (!empty($context->sitewide)) {
      context_set($context->namespace, $context->attribute, $context->value);
    }
  }
}