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