Commit efb3cc5a authored by fearlsgroove's avatar fearlsgroove Committed by Colan Schwartz

Issue #1018834 by fearlsgroove, ttkaminski | Rob_Feature: Add a no-context...

Issue #1018834 by fearlsgroove, ttkaminski | Rob_Feature: Add a no-context condition, except for the default site-wide one.
parent 536de408
......@@ -319,6 +319,9 @@ function context_context_page_condition() {
if ($plugin = context_get_plugin('condition', 'menu')) {
$plugin->execute();
}
if ($plugin = context_get_plugin('condition', 'default')) {
$plugin->execute(1);
}
if ($plugin = context_get_plugin('condition', 'context')) {
$plugin->execute();
}
......
......@@ -26,6 +26,11 @@ function _context_context_registry() {
'description' => t('Should this context always be set? If <strong>true</strong>, this context will be active across your entire site.'),
'plugin' => 'context_condition_sitewide',
),
'default' => array(
'title' => t('Default context'),
'description' => t('This context will be set if no other context is active except sitewide contexts.'),
'plugin' => 'context_condition_default',
),
'path' => array(
'title' => t('Path'),
'description' => t('Set this context when any of the paths above match the page path. Put each path on a separate line. You can use the <code>*</code> character (asterisk) as a wildcard and the <code>~</code> character (tilde) to exclude one or more paths. Use &lt;front&gt; for the site front page.'),
......@@ -194,6 +199,14 @@ function _context_context_plugins() {
'parent' => 'context_condition',
),
);
$plugins['context_condition_default'] = array(
'handler' => array(
'path' => drupal_get_path('module', 'context') . '/plugins',
'file' => 'context_condition_default.inc',
'class' => 'context_condition_default',
'parent' => 'context_condition',
),
);
$plugins['context_condition_path'] = array(
'handler' => array(
'path' => drupal_get_path('module', 'context') . '/plugins',
......
<?php
/**
* Simple condition that sets context active if no other non-default and non
* sitewide context is active.
*/
class context_condition_default extends context_condition {
function condition_values() {
return array('context_condition_default' => t('Default context'));
}
function editor_form($context = NULL) {
$form = parent::editor_form($context);
$form[1]['#title'] = t('Default context');
$form['#weight'] = -10;
return $form;
}
function execute() {
if ($this->condition_used()) {
$active_contexts = context_active_contexts();
foreach ($active_contexts as $name => $context) {
foreach (array_keys($context->conditions) as $cond) {
if (!in_array($cond, array('default', 'sitewide'))) {
return;
}
}
}
foreach ($this->get_contexts('context_condition_default') as $context) {
$this->condition_met($context, 'context_condition_default');
}
}
}
}
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