[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/ctools/plugins/access/ -> context_exists.inc (source)

   1  <?php
   2  // $Id: context_exists.inc,v 1.1.2.3 2010/02/23 21:09:32 merlinofchaos Exp $
   3  
   4  /**
   5   * @file
   6   * Plugin to provide access control/visibility based on existence of a specified context
   7   */
   8  
   9  $plugin = array(
  10    'title' => t("Context exists"),
  11    'description' => t('Control access by whether or not a context exists and contains data.'),
  12    'callback' => 'ctools_context_exists_ctools_access_check',
  13    'settings form' => 'ctools_context_exists_ctools_access_settings',
  14    'summary' => 'ctools_context_exists_ctools_access_summary',
  15    'required context' => new ctools_context_required(t('Context'), 'any'),
  16    'defaults' => array('exists' => TRUE),
  17  );
  18  
  19  /**
  20   * Settings form
  21   */
  22  function ctools_context_exists_ctools_access_settings(&$form, &$form_state, $conf) {
  23    $form['settings']['exists'] = array(
  24      '#type' => 'radios',
  25      '#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."),
  26      '#options' => array(TRUE => t('Exists'), FALSE => t("Doesn't exist")),
  27      '#default_value' => $conf['exists'],
  28    );
  29  }
  30  
  31  /**
  32   * Check for access
  33   */
  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']));
  39  }
  40  
  41  /**
  42   * Provide a summary description based upon the specified context
  43   */
  44  function ctools_context_exists_ctools_access_summary($conf, $context) {
  45    if (!empty($conf['exists'])) {
  46      return t('@identifier exists', array('@identifier' => $context->identifier));
  47    }
  48    else {
  49      return t('@identifier does not exist', array('@identifier' => $context->identifier));
  50    }
  51  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7