summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.txt1
-rw-r--r--plugins/access/context_exists.inc51
2 files changed, 52 insertions, 0 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 6ae591b..7831d48 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -7,6 +7,7 @@ ctools 6.x-1.x-dev
Introduce a "jump menu" tool which can be used to provide jump menus with a select.
Change plugins to no longer need magic function. Can now use $plugin = array(...) instead.
#652236 by alevine: Preserve pre-existing class when adding ajax functionality to form widgets.
+#588246 by brynbellomy: Add "context exists" access plugin.
ctools 6.x-1.2
==============
diff --git a/plugins/access/context_exists.inc b/plugins/access/context_exists.inc
new file mode 100644
index 0000000..86e4d49
--- /dev/null
+++ b/plugins/access/context_exists.inc
@@ -0,0 +1,51 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Plugin to provide access control/visibility based on existence of a specified context
+ */
+
+$plugin = array(
+ 'title' => t("Context exists"),
+ 'description' => t('Control access by whether or not a context exists and contains data.'),
+ 'callback' => 'ctools_context_exists_ctools_access_check',
+ 'settings form' => 'ctools_context_exists_ctools_access_settings',
+ 'summary' => 'ctools_context_exists_ctools_access_summary',
+ 'required context' => new ctools_context_required(t('Context'), 'any'),
+ 'defaults' => array('exists' => TRUE),
+);
+
+/**
+ * Settings form
+ */
+function ctools_context_exists_ctools_access_settings(&$form, &$form_state, $conf) {
+ $form['settings']['exists'] = array(
+ '#type' => 'radios',
+ '#description' => t("Check to see if the context exists (contains data) or does not exist (contains no data). For example, if a context is optional and the path does not contain an argument for that context, it will not exist."),
+ '#options' => array(TRUE => t('Exists'), FALSE => t("Doesn't exist")),
+ '#default_value' => $conf['exists'],
+ );
+}
+
+/**
+ * Check for access
+ */
+function ctools_context_exists_ctools_access_check($conf, $context) {
+ // xor returns false if the two bools are the same, and true if they are not.
+ // i.e, if we asked for context_exists and it does, return true.
+ // If we asked for context does not exist and it does, return false.
+ return (empty($context->data) xor empty($conf['context_exists']));
+}
+
+/**
+ * Provide a summary description based upon the specified context
+ */
+function ctools_context_exists_ctools_access_summary($conf, $context) {
+ if (!empty($conf['exists'])) {
+ return t('@identifier exists', array('@identifier' => $context->identifier));
+ }
+ else {
+ return t('@identifier does not exist', array('@identifier' => $context->identifier));
+ }
+}