context_condition_context.inc

  1. cis7 sites/all/modules/ulmus/context/plugins/context_condition_context.inc
  2. cle7 sites/all/modules/ulmus/context/plugins/context_condition_context.inc
  3. ecd7 sites/all/modules/ulmus/context/plugins/context_condition_context.inc
  4. elmsmedia7 sites/all/modules/ulmus/context/plugins/context_condition_context.inc
  5. harmony7 sites/all/modules/ulmus/context/plugins/context_condition_context.inc
  6. icor7 sites/all/modules/ulmus/context/plugins/context_condition_context.inc
  7. meedjum_blog7 sites/all/modules/ulmus/context/plugins/context_condition_context.inc
  8. mooc7 sites/all/modules/ulmus/context/plugins/context_condition_context.inc

Classes

Namesort descending Description
context_condition_context Expose active contexts as a context condition.

File

sites/all/modules/ulmus/context/plugins/context_condition_context.inc
View source
  1. <?php
  2. /**
  3. * Expose active contexts as a context condition.
  4. */
  5. class context_condition_context extends context_condition_path {
  6. function execute() {
  7. if ($this->condition_used()) {
  8. $active_contexts = array_keys(context_active_contexts());
  9. foreach ($this->get_contexts() as $context) {
  10. if (!in_array($context->name, $active_contexts, TRUE) && $values = $this->fetch_from_context($context, 'values')) {
  11. // Always check against the active contexts.
  12. if ($this->match(array_keys(context_active_contexts()), $values)) {
  13. $this->condition_met($context);
  14. }
  15. }
  16. }
  17. // If the list of active contexts has changed, we need to recurse.
  18. if ($active_contexts != array_keys(context_active_contexts())) {
  19. $this->execute();
  20. }
  21. }
  22. }
  23. /**
  24. * Retrieve all context conditions.
  25. *
  26. * This method is slightly adapted to context_condition::get_contexts() in
  27. * order to ensure that a context that is used as condition in another context
  28. * gets handled before.
  29. */
  30. function get_contexts($value = NULL) {
  31. $map = context_condition_map();
  32. $map = isset($map[$this->plugin]) ? $map[$this->plugin] : array();
  33. $contexts = array();
  34. // Add the contexts that are needed for conditions in the other contexts
  35. // first. Start with the negated ones first, as we can not unset a met
  36. // condition afterwards.
  37. krsort($map);
  38. foreach ($map as $key => $submap) {
  39. // Negated context conditions start with a "~".
  40. if (substr($key, 0, 1) == "~") {
  41. $key = substr($key, 1);
  42. }
  43. if (!isset($contexts[$key])) {
  44. $context = context_load($key);
  45. // Check if context exists. This will fail for wildcards.
  46. if ($context) {
  47. $contexts[$context->name] = $context;
  48. }
  49. }
  50. }
  51. foreach ($map as $key => $submap) {
  52. foreach ($submap as $name) {
  53. if (!isset($contexts[$name])) {
  54. $context = context_load($name);
  55. $contexts[$context->name] = $context;
  56. }
  57. }
  58. }
  59. return $contexts;
  60. }
  61. }