summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--views_content/plugins/contexts/view.inc64
-rw-r--r--views_content/plugins/relationships/view_from_argument.inc89
-rw-r--r--views_content/views_content.module69
3 files changed, 142 insertions, 80 deletions
diff --git a/views_content/plugins/contexts/view.inc b/views_content/plugins/contexts/view.inc
index 50f527e..1e926e4 100644
--- a/views_content/plugins/contexts/view.inc
+++ b/views_content/plugins/contexts/view.inc
@@ -25,20 +25,52 @@ $plugin = array(
'keyword' => 'view',
'context name' => 'view',
- /*
- 'convert list' => 'views_content_context_view_convert_list',
- 'convert' => 'views_content_context_view_convert',
- */
-
- /*
- 'placeholder form' => array(
- '#type' => 'textfield',
- '#description' => t('Enter the node ID of a node for this context.'),
- ),
- */
+ 'get child' => 'views_content_context_view_get_child',
+ 'get children' => 'views_content_context_view_get_children',
);
-function views_content_context_view_create($empty, $data = NULL, $conf = FALSE) {
+function views_content_context_view_get_child($plugin, $parent, $child) {
+ list($name, $id) = explode('-', $child, 2);
+ $view = views_get_view($name);
+ if (!$view) {
+ return;
+ }
+
+ $view->set_display($id);
+ if ($view->current_display != $id) {
+ return;
+ }
+
+ $info = _views_content_get_context_from_display($view, $id, $parent, FALSE);
+ if ($info) {
+ return $info;
+ }
+ return;
+}
+
+function views_content_context_view_get_children($plugin, $parent) {
+ $types = array(
+ 'view' => $plugin,
+ );
+
+ // We're keeping the 'view' context around for legacy reasons but
+ // we want to disable the UI so you can't add it that way anymore.
+ $types['view']['no ui'] = TRUE;
+
+ $views = views_get_applicable_views('returns context');
+ foreach ($views as $data) {
+ list($view, $id) = $data;
+ $info = _views_content_get_context_from_display($view, $id, $parent, FALSE);
+ if ($info) {
+ $info['no required context ui'] = TRUE;
+ $types[$info['name']] = $info;
+ }
+ }
+
+ return $types;
+}
+
+function views_content_context_view_create($empty, $data = NULL, $conf = FALSE, $plugin = array()) {
$context = new ctools_context('view');
$context->plugin = 'view';
@@ -48,15 +80,21 @@ function views_content_context_view_create($empty, $data = NULL, $conf = FALSE)
if ($conf) {
if (is_array($data) && !empty($data['view'])) {
+ // This code is left in for backward compatibility. Will not be used
+ // with child plugins.
list($name, $display_id) = explode(':', $data['view'], 2);
$data = views_get_view($name);
if ($data) {
$data->set_display($display_id);
}
}
+ else if (!empty($plugin['view name'])) {
+ $data = views_get_view($plugin['view name']);
+ $data->set_display($plugin['view display id']);
+ }
}
- if (is_object($data)) {
+ if (is_object($data) && $data->current_display != 'default') {
// We don't store the loaded view as we don't want the view object
// cached. However, in order to extract it you can use:
// @code
diff --git a/views_content/plugins/relationships/view_from_argument.inc b/views_content/plugins/relationships/view_from_argument.inc
index 49082ed..4da5fe5 100644
--- a/views_content/plugins/relationships/view_from_argument.inc
+++ b/views_content/plugins/relationships/view_from_argument.inc
@@ -19,82 +19,37 @@ $plugin = array(
);
function views_content_view_from_argument_get_child($plugin, $parent, $child) {
- $plugins = views_content_view_from_argument_get_children($plugin, $parent);
- return $plugins[$parent . ':' . $child];
-}
-
-function views_content_view_from_argument_get_children($plugin, $parent) {
- $types = array();
- // It can be fairly intensive to calculate this, so let's cache this in the
- // cache_views table. The nice thing there is that if views ever change, that
- // table will always be cleared. Except for the occasional default view, so
- // we must use the Views caching functions in order to respect Views caching
- // settings.
- views_include('cache');
- $data = views_cache_get('views_context_views', TRUE);
- if (!empty($data->data)) {
- $types = $data->data;
- }
-
- if (empty($types)) {
- $types = array();
-
- $views = views_get_all_views();
-
- foreach ($views as $view) {
- if (!empty($view->disabled)) {
- continue;
- }
-
- $view->init_display();
-
- foreach ($view->display as $id => $display) {
- if (empty($display->handler->context_display)) {
- continue;
- }
-
- $info = _views_content_context_relationships($view, $display, $parent);
- if ($info) {
- $types[$parent . ':' . $view->name . '-' . $id] = $info;
- }
- }
-
- $view->destroy();
- }
- views_cache_set('views_context_views', $types, TRUE);
+ list($name, $id) = explode('-', $child, 2);
+ $view = views_get_view($name);
+ if (!$view) {
+ return;
}
- return $types;
-}
-
-function _views_content_context_relationships($view, $display, $parent) {
- // Ensure the handler is the right type, as Views will fall back to
- // the default display if something is broken:
- if (get_class($display->handler) != 'views_content_plugin_display_ctools_context') {
+ $view->set_display($id);
+ if ($view->current_display != $id) {
return;
}
- $title = views_content_get_display_title($view, $display->id, 'admin_title');
+ $info = _views_content_get_context_from_display($view, $id, $parent, TRUE);
+ if ($info) {
+ return $info;
+ }
+ return;
+}
- $description = $view->description;
- $contexts = array();
+function views_content_view_from_argument_get_children($plugin, $parent) {
+ $types = array();
- $arguments = $display->handler->get_argument_input();
- ctools_include('views');
- foreach ($arguments as $argument) {
- $argument['label'] = $argument['name'] ? $argument['name'] : '';
- $contexts[] = ctools_views_get_argument_context($argument);
+ $views = views_get_applicable_views('returns context');
+ foreach ($views as $data) {
+ list($view, $id) = $data;
+ $info = _views_content_get_context_from_display($view, $id, $parent, TRUE);
+ if ($info) {
+ $types[$info['name']] = $info;
+ }
}
- return array(
- 'title' => $title,
- 'description' => filter_xss_admin($description),
- 'required context' => $contexts,
- 'keyword' => 'view',
- 'context' => 'views_content_view_from_argument_context',
- 'context name' => $view->name . '-' . $display->id,
- 'name' => $parent . ':' . $view->name . '-' . $display->id,
- );
+ return $types;
}
/**
diff --git a/views_content/views_content.module b/views_content/views_content.module
index b7f8510..e5074f5 100644
--- a/views_content/views_content.module
+++ b/views_content/views_content.module
@@ -212,3 +212,72 @@ function views_content_get_display_label($view, $display_id) {
$title = $display_id == 'default' ? t('Master') : $view->display[$display_id]->display_title;
return $title;
}
+
+/**
+ * Get the child plugin for a view context display.
+ *
+ * This can return both the context and relationship style. The
+ * $required parameter is used to distinguish if context is required
+ * or not, so we know whether we need it suitable as a pure context
+ * (i.e, no context required) or a relationship (i.e, context required).
+ */
+function _views_content_get_context_from_display($view, $id, $parent, $required = TRUE) {
+ $title = views_content_get_display_title($view, $id, 'admin_title');
+
+ $description = $view->description;
+ $contexts = array();
+
+ $arguments = $view->display_handler->get_argument_input();
+ ctools_include('views');
+ foreach ($arguments as $argument) {
+ $argument['label'] = $argument['name'] ? $argument['name'] : '';
+ $contexts[] = ctools_views_get_argument_context($argument);
+ }
+
+ $pass = FALSE;
+ if ($required) {
+ // If context is required, make sure we have at least one optional
+ // or required context.
+ foreach ($contexts as $context) {
+ if (is_object($context)) {
+ $pass = TRUE;
+ break;
+ }
+ }
+
+ if (!$pass) {
+ return;
+ }
+ }
+ else {
+ // If context is not required, then having any required context
+ // causes a fail.
+ foreach ($contexts as $context) {
+ if (is_object($context) && get_class($context) == 'ctools_context_required') {
+ return;
+ }
+ }
+
+ // Since we know we don't want contexts, we an unset this now.
+ $contexts = array();
+ }
+
+ if ($required) {
+ $function = 'views_content_view_from_argument_context';
+ }
+ else {
+ $function = 'views_content_context_view_create';
+ }
+
+ return array(
+ 'title' => $title,
+ 'description' => filter_xss_admin($description),
+ 'required context' => $contexts,
+ 'keyword' => 'view',
+ 'context' => $function,
+ 'context name' => $view->name,
+ 'name' => $parent . ':' . $view->name . '-' . $id,
+ 'view name' => $view->name,
+ 'view display id' => $id,
+ );
+}