t("Context exists"), 'description' => t('Control access by context existence.'), 'callback' => 'bryn_ctools_context_exists_ctools_access_check', 'settings form' => 'bryn_ctools_context_exists_ctools_access_settings', 'settings form submit' => 'bryn_ctools_context_exists_ctools_access_settings_submit', 'summary' => 'bryn_ctools_context_exists_ctools_access_summary', 'all contexts' => TRUE, ); } /** * Settings form */ function bryn_ctools_context_exists_ctools_access_settings(&$form, &$form_state, $conf) { $contexts = array(); foreach ($form_state['contexts'] as $key => $context) { // The global logged-in-user context should be dealt with using the user role access plugin if ($key != 'logged-in-user') $contexts[$key] = $context->keyword . ' (' . $context->identifier . ')'; } $form['settings']['which_context'] = array( '#type' => 'select', '#title' => t('Which context?'), '#options' => $contexts, '#default_value' => $conf['which_context'], ); $form['settings']['context_exists'] = array( '#type' => 'radios', '#title' => t('Exists or doesn\'t exist?'), '#options' => array('1' => t('Exists'), '0' => t('Doesn\'t exist')), '#default_value' => $conf['context_exists'], '#description' => t('Context exists or doesn\'t exist?'), ); } function bryn_ctools_context_exists_ctools_access_settings_submit(&$form, &$form_state) { $context = $form_state['contexts'][$form_state['values']['settings']['which_context']]; $form_state['values']['settings']['context_readable'] = $context->keyword . ' (' . $context->identifier . ')'; } /** * Check for access */ function bryn_ctools_context_exists_ctools_access_check($conf, $contexts) { if (empty($contexts)) { return FALSE; } if (isset($contexts[$conf['which_context']]->data) && $conf['context_exists'] == '1')) { return TRUE; } else if (!isset($contexts[$conf['which_context']]->data) && $conf['context_exists'] == '0')) { return TRUE; } else { return FALSE; } } /** * Provide a summary description based upon the specified context */ function bryn_ctools_context_exists_ctools_access_summary($conf, $contexts) { return t('Context \'!context\' !exists', array('!context' => $conf['context_readable'], '!exists' => $conf['context_exists'] ? 'exists' : 'doesn\'t exist') ); }