function context_set_by_condition in Context 6.2
Same name and namespace in other branches
- 6 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_context_page_condition in ./
context.core.inc - Implementation of hook_context_page_condition().
- context_contrib_node_condition in context_contrib/
context_contrib.module - Centralized node condition call function for the ever increasing number of ways to get at a node view / node form.
- context_contrib_views_pre_view in context_contrib/
context_contrib.module - Implementation of hook_views_pre_view().
- context_form_comment_form_alter in ./
context.core.inc - Implementation of hook_form_alter() for comment_form.
- context_node_condition in ./
context.core.inc - Centralized node condition call function for the ever increasing number of ways to get at a node view / node form.
File
- ./
context.module, line 609
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;
}