You are here

function context_contexts in Context 6.2

Same name and namespace in other branches
  1. 6 context.module \context_contexts()

Provides an array of all contexts provided by modules and in the database.

Parameters

$reset: Boolean to clear the static cached array of contexts.

Return value

An array of context objects.

5 calls to context_contexts()
context_enabled_contexts in ./context.module
Retrieves all enabled contexts from the cache.
context_ui_bulk_export in context_ui/context_ui.admin.inc
Export multiple contexts
context_ui_confirm in context_ui/context_ui.admin.inc
Provide a form to confirm one of the provided actions.
context_ui_menu_load in context_ui/context_ui.module
Helper loader to parse menu arguments and load contexts accordingly.
context_ui_preprocess_context_ui_list_contexts in context_ui/context_ui.admin.inc
Preprocess the contexts list theme

File

./context.module, line 332

Code

function context_contexts($reset = FALSE) {
  static $contexts;
  if (!$contexts || $reset) {
    $contexts = array();
    foreach (module_implements('context_default_contexts') as $module) {
      $function = $module . '_context_default_contexts';
      $c = call_user_func($function);
      if (!empty($c)) {
        foreach ($c as $context) {
          $context = (object) $context;
          $context->type = CONTEXT_STORAGE_DEFAULT;
          $identifier = "{$context->namespace}-{$context->attribute}-{$context->value}";
          $contexts[$identifier] = $context;
        }
      }
    }

    // Allow other modules to alter contexts
    drupal_alter('context_default_contexts', $contexts);

    // Collect normal & overridden contexts
    $result = db_query("SELECT * FROM {context} ORDER BY namespace ASC, attribute ASC, value ASC");
    while ($context = db_fetch_object($result)) {
      $context = context_unpack_context($context);
      $key = "{$context->namespace}-{$context->attribute}-{$context->value}";
      if (isset($contexts[$key])) {
        $contexts[$key] = $context;
        $contexts[$key]->type = CONTEXT_STORAGE_OVERRIDDEN;
      }
      else {
        $contexts[$key] = $context;
        $contexts[$key]->type = CONTEXT_STORAGE_NORMAL;
      }
    }

    // Mark the status of each context
    foreach ($contexts as $key => $context) {
      $contexts[$key]->status = context_status($context);
    }
  }
  return $contexts;
}