context_condition_views.inc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. class context_condition_views extends context_condition {
  3. /**
  4. * Generate a list of database and module provided views.
  5. */
  6. function condition_values() {
  7. $enabled_views = array();
  8. $views = views_get_all_views();
  9. ksort($views);
  10. foreach ($views as $view) {
  11. if (!isset($views[$view->name]->disabled) || !$views[$view->name]->disabled) {
  12. $enabled_views[$view->name] = check_plain($view->name);
  13. // Provide more granular options for each page display
  14. $displays = array();
  15. foreach ($view->display as $id => $display) {
  16. if ($display->display_plugin == 'page') {
  17. $displays[$view->name . ":" . $id] = check_plain("-- {$display->display_title}");
  18. }
  19. }
  20. $enabled_views += $displays;
  21. }
  22. }
  23. return $enabled_views;
  24. }
  25. function execute($view) {
  26. switch ($view->display_handler->display->display_plugin) {
  27. case 'page':
  28. case 'calendar':
  29. // Set contexts for this view.
  30. foreach ($this->get_contexts($view->name) as $context) {
  31. $this->condition_met($context, $view->name);
  32. }
  33. // Set any contexts associated with the current display
  34. if (!empty($view->current_display)) {
  35. foreach ($this->get_contexts("{$view->name}:{$view->current_display}") as $context) {
  36. $this->condition_met($context, "{$view->name}:{$view->current_display}");
  37. }
  38. }
  39. break;
  40. }
  41. }
  42. }