You are here

class ctools_context_optional in Chaos Tool Suite (ctools) 6

Same name and namespace in other branches
  1. 7 includes/context.inc \ctools_context_optional

Used to compare to see if a list of contexts match an optional context. This can produce empty contexts to use as placeholders.

Hierarchy

Expanded class hierarchy of ctools_context_optional

File

includes/context.inc, line 182
Contains code related to the ctools system of 'context'.

View source
class ctools_context_optional extends ctools_context_required {
  var $required = FALSE;
  function ctools_context_optional() {
    $args = func_get_args();
    call_user_func_array(array(
      $this,
      'ctools_context_required',
    ), $args);
  }

  /**
   * Add the 'empty' context which is possible for optional
   */
  function add_empty(&$contexts) {
    $context = new ctools_context('any');
    $context->title = t('No context');
    $context->identifier = t('No context');
    $contexts = array_merge(array(
      'empty' => $context,
    ), $contexts);
  }
  function filter($contexts) {
    $this
      ->add_empty($contexts);
    return parent::filter($contexts);
  }
  function select($contexts, $context) {
    $this
      ->add_empty($contexts);
    if (empty($context)) {
      return $contexts['empty'];
    }
    $result = parent::select($contexts, $context);

    // Don't flip out if it can't find the context; this is optional, put
    // in an empty.
    if ($result == FALSE) {
      $result = $contexts['empty'];
    }
    return $result;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ctools_context_optional::$required property Test to see if this context is required. Overrides ctools_context_required::$required
ctools_context_optional::add_empty function Add the 'empty' context which is possible for optional
ctools_context_optional::ctools_context_optional function
ctools_context_optional::filter function Overrides ctools_context_required::filter
ctools_context_optional::select function Overrides ctools_context_required::select
ctools_context_required::$keywords property
ctools_context_required::$title property If set, the title will be used in the selector to identify the context. This is very useful when multiple contexts are required to inform the user will be used for what.
ctools_context_required::ctools_context_required function