You are here

function context_set_by_condition in Context 6

Same name and namespace in other branches
  1. 6.2 context.module \context_set_by_condition()

Sets a namespace-attribute-value context that has been associated with the provided condition.

Parameters

$type: The condition type to be matched.

$id: A value to match against.

$force: Boolean param to force the setting of a context value even if a value for the found namespace/attribute is already set. Defaults to FALSE.

Return value

True if one or more contexts were set. False if no items/contexts matched.

7 calls to context_set_by_condition()
context_contrib_nodeapi in context_contrib/context_contrib.module
Implementation of hook_nodeapi().
context_contrib_views_pre_view in context_contrib/context_contrib.module
Implementation of hook_views_pre_view().
context_form_alter in ./context.core.inc
Implementation of hook_form_alter().
context_form_comment_form_alter in ./context.core.inc
Implementation of hook_form_alter() for comment_form.
context_init in ./context.module
Implementation of hook_init().

... See full list

File

./context.module, line 606

Code

function context_set_by_condition($type, $id, $force = FALSE) {
  $map = context_condition_map();
  $set = FALSE;
  if (!empty($map[$type]) && !empty($map[$type][$id])) {
    $contexts = context_enabled_contexts();
    $identifiers = $map[$type][$id];
    foreach ($identifiers as $identifier) {
      $context = !empty($contexts[$identifier]) ? $contexts[$identifier] : FALSE;
      if ($context) {

        // If this context already has a value, don't alter it.
        if (!context_isset($context->namespace, $context->attribute) || $force) {
          context_set($context->namespace, $context->attribute, $context->value);
          $set = TRUE;
        }
      }
    }
  }
  return $set;
}