Commit 8e485022 authored by Colan Schwartz's avatar Colan Schwartz

Issue #2126747 by colan: Add option to AND terms for the Context condition.

parent f1a8021b
......@@ -322,6 +322,9 @@ function context_context_page_condition() {
if ($plugin = context_get_plugin('condition', 'context')) {
$plugin->execute();
}
if ($plugin = context_get_plugin('condition', 'context_all')) {
$plugin->execute();
}
}
/**
......
......@@ -7,10 +7,15 @@ function _context_context_registry() {
$registry = array();
$registry['conditions'] = array(
'context' => array(
'title' => t('Context'),
'description' => t('Set this context on the basis of other active contexts. Put each context on a separate line. You can use the <code>*</code> character (asterisk) as a wildcard and the <code>~</code> character (tilde) to prevent this context from activating if the listed context is active. Other contexts which use context conditions can not be used to exclude this context from activating.'),
'title' => t('Context (any)'),
'description' => t('Set this context on the basis of other active contexts. Put each context on a separate line. The condition will pass if <em>any</em> of the contexts are active. You can use the <code>*</code> character (asterisk) as a wildcard and the <code>~</code> character (tilde) to prevent this context from activating if the listed context is active. Other contexts which use context conditions can not be used to exclude this context from activating.'),
'plugin' => 'context_condition_context',
),
'context_all' => array(
'title' => t('Context (all)'),
'description' => t('Set this context on the basis of other active contexts. Put each context on a separate line. The condition will pass only if <em>all</em> of the contexts are active. You can use the <code>*</code> character (asterisk) as a wildcard and the <code>~</code> character (tilde) to prevent this context from activating if the listed context is active. Other contexts which use context conditions can not be used to exclude this context from activating.'),
'plugin' => 'context_condition_context_all',
),
'node' => array(
'title' => t('Node type'),
'description' => t('Set this context when viewing a node page or using the add/edit form of one of these content types.'),
......@@ -160,6 +165,14 @@ function _context_context_plugins() {
'parent' => 'context_condition_path',
),
);
$plugins['context_condition_context_all'] = array(
'handler' => array(
'path' => drupal_get_path('module', 'context') . '/plugins',
'file' => 'context_condition_context_all.inc',
'class' => 'context_condition_context_all',
'parent' => 'context_condition_path',
),
);
$plugins['context_condition_node'] = array(
'handler' => array(
'path' => drupal_get_path('module', 'context') . '/plugins',
......
<?php
/**
* Expose active contexts as a context condition.
*/
class context_condition_context_all extends context_condition_path {
function execute() {
if ($this->condition_used()) {
$active_contexts = array_keys(context_active_contexts());
foreach ($this->get_contexts() as $context) {
// Only test contexts that haven't been activated yet,
// and have values set.
if (!in_array($context->name, $active_contexts, TRUE) && $values = $this->fetch_from_context($context, 'values')) {
// The condition is met if all contexts are active.
if (count(array_intersect($values, $active_contexts)) == count($values)) {
$this->condition_met($context);
}
}
}
// If the list of active contexts has changed, we need to recurse.
if ($active_contexts != array_keys(context_active_contexts())) {
$this->execute();
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment