5 * Plugin to provide access control/visibility based on existence of a specified context
9 'title' => t("Context exists"),
10 'description' => t('Control access by whether or not a context exists and contains data.'),
11 'callback' => 'ctools_context_exists_ctools_access_check',
12 'settings form' => 'ctools_context_exists_ctools_access_settings',
13 'summary' => 'ctools_context_exists_ctools_access_summary',
14 'required context' => new ctools_context_required(t('Context'), 'any', TRUE),
15 'defaults' => array('exists' => TRUE),
21 function ctools_context_exists_ctools_access_settings($form, &$form_state, $conf) {
22 $form['settings']['exists'] = array(
24 '#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."),
25 '#options' => array(TRUE => t('Exists'), FALSE => t("Doesn't exist")),
26 '#default_value' => $conf['exists'],
34 function ctools_context_exists_ctools_access_check($conf, $context) {
35 // xor returns false if the two bools are the same, and true if they are not.
36 // i.e, if we asked for context_exists and it does, return true.
37 // If we asked for context does not exist and it does, return false.
38 return (empty($context->data) xor !empty($conf['exists']));
42 * Provide a summary description based upon the specified context
44 function ctools_context_exists_ctools_access_summary($conf, $context) {
45 if (!empty($conf['exists'])) {
46 return t('@identifier exists', array('@identifier' => $context->identifier));
49 return t('@identifier does not exist', array('@identifier' => $context->identifier));