function context_ui_set in Context 5
Sets a namespace-attribute-value context that has been associated with the provided item.
Parameters
$type: The item type to be matched. Any of the currently supported context items types ("view", "node", etc.) can be specified.
$id: An array of string or integer ids of the context item to match. Individual ids are also accepted.
Return value
True if one or more contexts were set. False if no items/contexts matched.
5 calls to context_ui_set()
- context_ui_contrib_nodeapi in context_ui/
context_ui_contrib.module - Implementation of hook_nodeapi().
- context_ui_contrib_views_pre_query in context_ui/
context_ui_contrib.module - Implementation of hook_views_pre_query().
- context_ui_form_alter in context_ui/
context_ui.module - Implementation of hook_form_alter().
- context_ui_nodeapi in context_ui/
context_ui.module - Implementation of hook_nodeapi().
- context_ui_user in context_ui/
context_ui.module - Implementation of hook_user().
File
- context_ui/
context_ui.module, line 387
Code
function context_ui_set($type, $id) {
if (!is_array($id)) {
$id = array(
$id,
);
}
$set = false;
$result = db_query("\n SELECT c.namespace, c.attribute, c.value, c.cid FROM {context_ui_item} ci\n JOIN {context_ui} c ON ci.cid = c.cid\n WHERE ci.type = '%s' AND ci.id IN (" . substr(str_repeat("'%s',", count($id)), 0, -1) . ") AND c.status = 1", array_merge(array(
$type,
), $id));
while ($context = db_fetch_object($result)) {
// If this context already has a value, don't alter it.
if (!context_isset($context->namespace, $context->attribute)) {
context_set($context->namespace, $context->attribute, $context->value);
// Allow getters to respond to the set context
$context = context_ui_context('load', $context);
module_invoke_all('context_getter', $context);
// Store the cid of set contexts. Other parts of the stack may be interested.
$cid = context_get('context_ui', 'cid');
$cid = $cid ? $cid : array();
$cid[] = $context->cid;
context_set('context_ui', 'cid', $cid);
$set = true;
}
}
return $set;
}