1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Plugin to provide an relationship handler for a view by argument input settings.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Plugins are described by creating a $plugin array which will be used
|
10 |
|
|
* by the system that includes this file.
|
11 |
|
|
*/
|
12 |
|
|
$plugin = array(
|
13 |
|
|
'title' => t('View From Argument'),
|
14 |
|
|
'description' => t('Creates a view context from argument input settings.'),
|
15 |
|
|
'context' => 'views_content_view_from_argument_context',
|
16 |
|
|
'get child' => 'views_content_view_from_argument_get_child',
|
17 |
|
|
'get children' => 'views_content_view_from_argument_get_children',
|
18 |
|
|
);
|
19 |
|
|
|
20 |
|
|
function views_content_view_from_argument_get_child($plugin, $parent, $child) {
|
21 |
|
|
list($name, $id) = explode('-', $child, 2);
|
22 |
|
|
$view = views_get_view($name);
|
23 |
|
|
if (!$view) {
|
24 |
|
|
return;
|
25 |
|
|
}
|
26 |
|
|
|
27 |
|
|
$view->set_display($id);
|
28 |
|
|
if ($view->current_display != $id) {
|
29 |
|
|
return;
|
30 |
|
|
}
|
31 |
|
|
|
32 |
|
|
$info = _views_content_get_context_from_display($view, $id, $parent, TRUE);
|
33 |
|
|
if ($info) {
|
34 |
|
|
return $info;
|
35 |
|
|
}
|
36 |
|
|
return;
|
37 |
|
|
}
|
38 |
|
|
|
39 |
|
|
function views_content_view_from_argument_get_children($plugin, $parent) {
|
40 |
|
|
$types = array();
|
41 |
|
|
|
42 |
|
|
$views = views_get_applicable_views('returns context');
|
43 |
|
|
foreach ($views as $data) {
|
44 |
|
|
list($view, $id) = $data;
|
45 |
|
|
$info = _views_content_get_context_from_display($view, $id, $parent, TRUE);
|
46 |
|
|
if ($info) {
|
47 |
|
|
$types[$info['name']] = $info;
|
48 |
|
|
}
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
return $types;
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
/**
|
55 |
|
|
* Return a new context based on an existing context.
|
56 |
|
|
*/
|
57 |
|
|
function views_content_view_from_argument_context($contexts, $conf) {
|
58 |
|
|
$name = $conf['name'];
|
59 |
|
|
list($plugin, $view_data) = explode(':', $name);
|
60 |
|
|
list($view_name, $display_id) = explode('-', $view_data);
|
61 |
|
|
$keys = array_keys($conf['context']);
|
62 |
|
|
|
63 |
|
|
if (empty($contexts[$keys[0]]->data)) {
|
64 |
|
|
return ctools_context_create_empty('view', NULL);
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
// Load our view up.
|
68 |
|
|
$data = views_get_view($view_name);
|
69 |
|
|
if ($data) {
|
70 |
|
|
// Set the display.
|
71 |
|
|
$data->set_display($display_id);
|
72 |
|
|
$context_keys = array_keys($contexts);
|
73 |
|
|
foreach ($data->display_handler->get_argument_input() as $id => $argument) {
|
74 |
|
|
if ($argument['type'] == 'context') {
|
75 |
|
|
$key = array_shift($context_keys);
|
76 |
|
|
if (isset($contexts [$key])) {
|
77 |
|
|
if (strpos($argument['context'], '.')) {
|
78 |
|
|
list($context, $converter) = explode('.', $argument['context'], 2);
|
79 |
|
|
$args[] = ctools_context_convert_context($contexts[$key], $converter, array('sanitize' => FALSE));
|
80 |
|
|
}
|
81 |
|
|
else {
|
82 |
|
|
$args[] = $contexts[$key]->argument;
|
83 |
|
|
}
|
84 |
|
|
}
|
85 |
|
|
}
|
86 |
|
|
}
|
87 |
|
|
// remove any trailing NULL arguments as these are non-args:
|
88 |
|
|
while (count($args) && end($args) === NULL) {
|
89 |
|
|
array_pop($args);
|
90 |
|
|
}
|
91 |
|
|
$data->set_arguments($args);
|
92 |
|
|
if ($path = $data->display_handler->get_option('inherit_panels_path')) {
|
93 |
|
|
$data->override_path = $_GET['q'];
|
94 |
|
|
}
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
if (isset($contexts[$keys[0]]->data)) {
|
98 |
|
|
return ctools_context_create('view', $data);
|
99 |
|
|
}
|
100 |
|
|
} |