views_handler_area_view.inc

Definition of views_handler_area_view.

File

handlers/views_handler_area_view.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_area_view.
  5. */
  6. /**
  7. * Views area handlers. Insert a view inside of an area.
  8. *
  9. * @ingroup views_area_handlers
  10. */
  11. class views_handler_area_view extends views_handler_area {
  12. function option_definition() {
  13. $options = parent::option_definition();
  14. $options['view_to_insert'] = array('default' => '');
  15. $options['inherit_arguments'] = array('default' => FALSE, 'bool' => TRUE);
  16. return $options;
  17. }
  18. /**
  19. * Default options form that provides the label widget that all fields
  20. * should have.
  21. */
  22. function options_form(&$form, &$form_state) {
  23. parent::options_form($form, $form_state);
  24. $view_display = $this->view->name . ':' . $this->view->current_display;
  25. $options = array('' => t('-Select-'));
  26. $options += views_get_views_as_options(FALSE, 'all', $view_display, FALSE, TRUE);
  27. $form['view_to_insert'] = array(
  28. '#type' => 'select',
  29. '#title' => t('View to insert'),
  30. '#default_value' => $this->options['view_to_insert'],
  31. '#description' => t('The view to insert into this area.'),
  32. '#options' => $options,
  33. );
  34. $form['inherit_arguments'] = array(
  35. '#type' => 'checkbox',
  36. '#title' => t('Inherit contextual filters'),
  37. '#default_value' => $this->options['inherit_arguments'],
  38. '#description' => t('If checked, this view will receive the same contextual filters as its parent.'),
  39. );
  40. }
  41. /**
  42. * Render the area
  43. */
  44. function render($empty = FALSE) {
  45. if (!empty($this->options['view_to_insert'])) {
  46. list($view_name, $display_id) = explode(':', $this->options['view_to_insert']);
  47. $view = views_get_view($view_name);
  48. if (empty($view) || !$view->access($display_id)) {
  49. return;
  50. }
  51. $view->set_display($display_id);
  52. // Avoid recursion
  53. $view->parent_views += $this->view->parent_views;
  54. $view->parent_views[] = "$view_name:$display_id";
  55. // Check if the view is part of the parent views of this view
  56. $search = "$view_name:$display_id";
  57. if (in_array($search, $this->view->parent_views)) {
  58. drupal_set_message(t("Recursion detected in view @view display @display.", array('@view' => $view_name, '@display' => $display_id)), 'error');
  59. }
  60. else {
  61. if (!empty($this->options['inherit_arguments']) && !empty($this->view->args)) {
  62. return $view->preview($display_id, $this->view->args);
  63. }
  64. else {
  65. return $view->preview($display_id);
  66. }
  67. }
  68. }
  69. return '';
  70. }
  71. }