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 ($view = $this->loadView()) {
|
55
|
if (!empty($this->options['inherit_arguments']) && !empty($this->view->args)) {
|
56
|
return $view->preview(NULL, $this->view->args);
|
57
|
}
|
58
|
else {
|
59
|
return $view->preview(NULL);
|
60
|
}
|
61
|
}
|
62
|
return '';
|
63
|
}
|
64
|
|
65
|
/**
|
66
|
* Loads the used view for rendering.
|
67
|
*
|
68
|
* @return \view|NULL
|
69
|
* The loaded view or NULL, in case the view was not loadable / recursion
|
70
|
* got detected / access got denied.
|
71
|
*/
|
72
|
protected function loadView() {
|
73
|
if (empty($this->options['view_to_insert'])) {
|
74
|
return NULL;
|
75
|
}
|
76
|
list($view_name, $display_id) = explode(':', $this->options['view_to_insert']);
|
77
|
|
78
|
$view = views_get_view($view_name);
|
79
|
if (empty($view) || !$view->access($display_id)) {
|
80
|
return NULL;
|
81
|
}
|
82
|
$view->set_display($display_id);
|
83
|
|
84
|
// Avoid recursion.
|
85
|
$view->parent_views += $this->view->parent_views;
|
86
|
$view->parent_views[] = "$view_name:$display_id";
|
87
|
|
88
|
// Check if the view is part of the parent views of this view.
|
89
|
$search = "$view_name:$display_id";
|
90
|
if (in_array($search, $this->view->parent_views)) {
|
91
|
drupal_set_message(t("Recursion detected in view @view display @display.", array('@view' => $view_name, '@display' => $display_id)), 'error');
|
92
|
return NULL;
|
93
|
}
|
94
|
|
95
|
return $view;
|
96
|
}
|
97
|
|
98
|
}
|