You are here

function _context_prefix_set in Context 5

Static cache function for setting + storing any prefixed contexts that are present on this page's request.

2 calls to _context_prefix_set()
context_prefix_get in context_prefix/context_prefix.module
Get wrapper for _context_prefix_set()
context_prefix_set in context_prefix/context_prefix.module
Set wrapper for _context_prefix_set()

File

context_prefix/context_prefix.module, line 349

Code

function _context_prefix_set($op = 'set', $type = CONTEXT_PREFIX_PATH, $prefix = '', $info = array()) {
  static $used;
  if (!$used) {
    $used = new context_prefix_cache();
  }
  switch ($op) {
    case 'set':

      // Store prefix for url rewriting later on in the stack
      $info['prefix'] = $prefix;
      $used
        ->add($type, $info, false);

      // Fire the provider callback
      if ($info['provider'] && $info['id']) {

        // Fire the provider callback
        $providers = context_prefix_providers();
        $callback = $providers[$info['provider']]['callback'];
        $args = isset($providers[$info['provider']]['callback arguments']) ? $providers[$info['provider']]['callback arguments'] : array();
        $args[] = $info['id'];
        if (function_exists($callback)) {
          call_user_func_array($callback, $args);
        }
      }
      break;
    case 'get':
      if ($type === 'all') {
        return $used
          ->get();
      }
      else {
        return $used
          ->get($type);
      }
  }
}