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.
11 * Plugins are described by creating a $plugin array which will be used
12 * by the system that includes this file.
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',
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',
23 'defaults' => array('view' => ''),
26 'context name' => 'view',
28 'get child' => 'views_content_context_view_get_child',
29 'get children' => 'views_content_context_view_get_children',
32 function views_content_context_view_get_child($plugin, $parent, $child) {
33 list($name, $id) = explode('-', $child, 2);
34 $view = views_get_view($name);
39 $view->set_display($id);
40 if ($view->current_display != $id) {
44 $info = _views_content_get_context_from_display($view, $id, $parent, FALSE);
51 function views_content_context_view_get_children($plugin, $parent) {
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;
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);
65 $info['no required context ui'] = TRUE;
66 $types[$info['name']] = $info;
73 function views_content_context_view_create($empty, $data = NULL, $conf = FALSE, $plugin = array()) {
74 $context = new ctools_context('view');
75 $context->plugin = 'view';
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);
88 $data->set_display($display_id);
91 else if (!empty($plugin['view name'])) {
92 $data = views_get_view($plugin['view name']);
93 $data->set_display($plugin['view display id']);
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:
101 // $output = views_content_context_get_output($context);
102 // $view = $output['view'];
104 $context->data = array(
105 'name' => $data->name,
106 'display' => $data->current_display,
107 'args' => $data->args,
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;
116 $context->restrictions['base'] = array($data->base_table);
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;
131 if (!empty($options)) {
132 natcasesort($options);
133 $form['view'] = array(
135 '#options' => $options,
136 '#title' => t('View'),
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>',
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.'));
158 * Provide a list of ways that this context can be converted to a string.
160 function views_content_context_view_convert_list() {
168 * Convert a context into a string.
170 function views_content_context_view_convert($context, $type) {