context_condition_default.inc 985 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. /**
  3. * Simple condition that sets context active if no other non-default and non
  4. * sitewide context is active.
  5. */
  6. class context_condition_default extends context_condition {
  7. function condition_values() {
  8. return array('context_condition_default' => t('Default context'));
  9. }
  10. function editor_form($context = NULL) {
  11. $form = parent::editor_form($context);
  12. $form[1]['#title'] = t('Default context');
  13. $form['#weight'] = -10;
  14. return $form;
  15. }
  16. function execute() {
  17. if ($this->condition_used()) {
  18. $active_contexts = context_active_contexts();
  19. foreach ($active_contexts as $name => $context) {
  20. foreach (array_keys($context->conditions) as $cond) {
  21. if (!in_array($cond, array('default', 'sitewide'))) {
  22. return;
  23. }
  24. }
  25. }
  26. foreach ($this->get_contexts('context_condition_default') as $context) {
  27. $this->condition_met($context, 'context_condition_default');
  28. }
  29. }
  30. }
  31. }