commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / ctools / views_content / plugins / contexts / view.inc
1 <?php
2
3 /**
4 * @file
5 *
6 * Plugin to provide a node context. A node context is a node wrapped in a
7 * context object that can be utilized by anything that accepts contexts.
8 */
9
10 /**
11 * Plugins are described by creating a $plugin array which will be used
12 * by the system that includes this file.
13 */
14 $plugin = array(
15 'title' => t("View"),
16 'description' => t('Loads a view result into a context that can then be displayed across a panel or turned into other contexts.'),
17 'context' => 'views_content_context_view_create',
18
19 'edit form' => 'views_content_context_view_settings_form',
20 'edit form validate' => 'views_content_context_view_settings_form_validate',
21 'edit form submit' => 'views_content_context_view_settings_form_submit',
22
23 'defaults' => array('view' => ''),
24
25 'keyword' => 'view',
26 'context name' => 'view',
27
28 'get child' => 'views_content_context_view_get_child',
29 'get children' => 'views_content_context_view_get_children',
30 );
31
32 function views_content_context_view_get_child($plugin, $parent, $child) {
33 list($name, $id) = explode('-', $child, 2);
34 $view = views_get_view($name);
35 if (!$view) {
36 return;
37 }
38
39 $view->set_display($id);
40 if ($view->current_display != $id) {
41 return;
42 }
43
44 $info = _views_content_get_context_from_display($view, $id, $parent, FALSE);
45 if ($info) {
46 return $info;
47 }
48 return;
49 }
50
51 function views_content_context_view_get_children($plugin, $parent) {
52 $types = array(
53 'view' => $plugin,
54 );
55
56 // We're keeping the 'view' context around for legacy reasons but
57 // we want to disable the UI so you can't add it that way anymore.
58 $types['view']['no ui'] = TRUE;
59
60 $views = views_get_applicable_views('returns context');
61 foreach ($views as $data) {
62 list($view, $id) = $data;
63 $info = _views_content_get_context_from_display($view, $id, $parent, FALSE);
64 if ($info) {
65 $info['no required context ui'] = TRUE;
66 $types[$info['name']] = $info;
67 }
68 }
69
70 return $types;
71 }
72
73 function views_content_context_view_create($empty, $data = NULL, $conf = FALSE, $plugin = array()) {
74 $context = new ctools_context('view');
75 $context->plugin = 'view';
76
77 if ($empty) {
78 return $context;
79 }
80
81 if ($conf) {
82 if (is_array($data) && !empty($data['view'])) {
83 // This code is left in for backward compatibility. Will not be used
84 // with child plugins.
85 list($name, $display_id) = explode(':', $data['view'], 2);
86 $data = views_get_view($name);
87 if ($data) {
88 $data->set_display($display_id);
89 }
90 }
91 else if (!empty($plugin['view name'])) {
92 $data = views_get_view($plugin['view name']);
93 $data->set_display($plugin['view display id']);
94 }
95 }
96
97 if (is_object($data) && $data->current_display != 'default') {
98 // We don't store the loaded view as we don't want the view object
99 // cached. However, in order to extract it you can use:
100 // @code
101 // $output = views_content_context_get_output($context);
102 // $view = $output['view'];
103 // @endcode
104 $context->data = array(
105 'name' => $data->name,
106 'display' => $data->current_display,
107 'args' => $data->args,
108 );
109
110 // At runtime, this can get populated. Once it is populated this
111 // object should not be cached.
112 $context->view = NULL;
113 $context->title = $data->get_title();
114 $context->argument = $data->name . ':' . $data->current_display;
115
116 $context->restrictions['base'] = array($data->base_table);
117
118 return $context;
119 }
120 }
121
122 function views_content_context_view_settings_form($form, &$form_state) {
123 $conf = $form_state['conf'];
124 $views = views_get_applicable_views('returns context');
125 foreach ($views as $data) {
126 list($view, $id) = $data;
127 $title = views_content_get_display_title($view, $id, 'admin_title');
128 $options[$view->name . ':' . $id] = $title;
129 }
130
131 if (!empty($options)) {
132 natcasesort($options);
133 $form['view'] = array(
134 '#type' => 'select',
135 '#options' => $options,
136 '#title' => t('View'),
137 );
138 }
139 else {
140 $form['view'] = array(
141 '#value' => '<p>' . t('There are currently no views with Context displays enabled. You should go to the view administration and add a Context display to use a view as a context.') . '</p>',
142 );
143 }
144
145 return $form;
146 }
147
148 /**
149 * Validate a node.
150 */
151 function views_content_context_view_settings_form_validate($form, &$form_state) {
152 if (empty($form_state['values']['view'])) {
153 form_error($form['view'], t('You must select a view.'));
154 }
155 }
156
157 /**
158 * Provide a list of ways that this context can be converted to a string.
159 */
160 function views_content_context_view_convert_list() {
161 $list = array(
162 );
163
164 return $list;
165 }
166
167 /**
168 * Convert a context into a string.
169 */
170 function views_content_context_view_convert($context, $type) {
171 switch ($type) {
172 }
173 }
174