Projet

Général

Profil

Paste
Télécharger (2,5 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / handlers / views_handler_area_view.inc @ 13755f8d

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of views_handler_area_view.
6
 */
7

    
8
/**
9
 * Views area handlers. Insert a view inside of an area.
10
 *
11
 * @ingroup views_area_handlers
12
 */
13
class views_handler_area_view extends views_handler_area {
14

    
15
  function option_definition() {
16
    $options = parent::option_definition();
17

    
18
    $options['view_to_insert'] = array('default' => '');
19
    $options['inherit_arguments'] = array('default' => FALSE, 'bool' => TRUE);
20
    return $options;
21
  }
22

    
23
  /**
24
   * Default options form that provides the label widget that all fields
25
   * should have.
26
   */
27
  function options_form(&$form, &$form_state) {
28
    parent::options_form($form, $form_state);
29

    
30
    $view_display = $this->view->name . ':' . $this->view->current_display;
31

    
32
    $options = array('' => t('-Select-'));
33
    $options += views_get_views_as_options(FALSE, 'all', $view_display, FALSE, TRUE);
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',
44
      '#title' => t('Inherit contextual filters'),
45
      '#default_value' => $this->options['inherit_arguments'],
46
      '#description' => t('If checked, this view will receive the same contextual filters as its parent.'),
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, $display_id) = explode(':', $this->options['view_to_insert']);
56

    
57
      $view = views_get_view($view_name);
58
      if (empty($view) || !$view->access($display_id)) {
59
        return;
60
      }
61
      $view->set_display($display_id);
62

    
63
      // Avoid recursion
64
      $view->parent_views += $this->view->parent_views;
65
      $view->parent_views[] = "$view_name:$display_id";
66

    
67
      // Check if the view is part of the parent views of this view
68
      $search = "$view_name:$display_id";
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' => $display_id)), 'error');
71
      }
72
      else {
73
        if (!empty($this->options['inherit_arguments']) && !empty($this->view->args)) {
74
          return $view->preview($display_id, $this->view->args);
75
        }
76
        else {
77
          return $view->preview($display_id);
78
        }
79
      }
80
    }
81
    return '';
82
  }
83
}