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
|
/**
|
16
|
* {@inheritdoc}
|
17
|
*/
|
18
|
public function option_definition() {
|
19
|
$options = parent::option_definition();
|
20
|
|
21
|
$options['view_to_insert'] = array('default' => '');
|
22
|
$options['inherit_arguments'] = array('default' => FALSE, 'bool' => TRUE);
|
23
|
return $options;
|
24
|
}
|
25
|
|
26
|
/**
|
27
|
* Default options form; provides the label widget all fields should have.
|
28
|
*/
|
29
|
public function options_form(&$form, &$form_state) {
|
30
|
parent::options_form($form, $form_state);
|
31
|
|
32
|
$view_display = $this->view->name . ':' . $this->view->current_display;
|
33
|
|
34
|
$options = array('' => t('-Select-'));
|
35
|
$options += views_get_views_as_options(FALSE, 'all', $view_display, FALSE, TRUE);
|
36
|
$form['view_to_insert'] = array(
|
37
|
'#type' => 'select',
|
38
|
'#title' => t('View to insert'),
|
39
|
'#default_value' => $this->options['view_to_insert'],
|
40
|
'#description' => t('The view to insert into this area.'),
|
41
|
'#options' => $options,
|
42
|
);
|
43
|
|
44
|
$form['inherit_arguments'] = array(
|
45
|
'#type' => 'checkbox',
|
46
|
'#title' => t('Inherit contextual filters'),
|
47
|
'#default_value' => $this->options['inherit_arguments'],
|
48
|
'#description' => t('If checked, this view will receive the same contextual filters as its parent.'),
|
49
|
);
|
50
|
}
|
51
|
|
52
|
/**
|
53
|
* Render the area.
|
54
|
*/
|
55
|
public function render($empty = FALSE) {
|
56
|
if ($view = $this->loadView()) {
|
57
|
if (!empty($this->options['inherit_arguments']) && !empty($this->view->args)) {
|
58
|
return $view->preview(NULL, $this->view->args);
|
59
|
}
|
60
|
else {
|
61
|
return $view->preview(NULL);
|
62
|
}
|
63
|
}
|
64
|
return '';
|
65
|
}
|
66
|
|
67
|
/**
|
68
|
* Loads the used view for rendering.
|
69
|
*
|
70
|
* @return \view|NULL
|
71
|
* The loaded view or NULL, in case the view was not loadable / recursion
|
72
|
* got detected / access got denied.
|
73
|
*/
|
74
|
protected function loadView() {
|
75
|
if (empty($this->options['view_to_insert'])) {
|
76
|
return NULL;
|
77
|
}
|
78
|
list($view_name, $display_id) = explode(':', $this->options['view_to_insert']);
|
79
|
|
80
|
$view = views_get_view($view_name);
|
81
|
if (empty($view) || !$view->access($display_id)) {
|
82
|
return NULL;
|
83
|
}
|
84
|
$view->set_display($display_id);
|
85
|
|
86
|
// Avoid recursion.
|
87
|
$view->parent_views += $this->view->parent_views;
|
88
|
$view->parent_views[] = "$view_name:$display_id";
|
89
|
|
90
|
// Check if the view is part of the parent views of this view.
|
91
|
$search = "$view_name:$display_id";
|
92
|
if (in_array($search, $this->view->parent_views)) {
|
93
|
drupal_set_message(t("Recursion detected in view @view display @display.", array('@view' => $view_name, '@display' => $display_id)), 'error');
|
94
|
return NULL;
|
95
|
}
|
96
|
|
97
|
return $view;
|
98
|
}
|
99
|
|
100
|
}
|