You are here

function ctools_context_converter_selector in Chaos Tool Suite (ctools) 7

Same name and namespace in other branches
  1. 6 includes/context.inc \ctools_context_converter_selector()

Create a select box to choose possible contexts.

This only creates a selector if there is actually a choice; if there is only one possible context, that one is silently assigned.

If an array of required contexts is provided, one selector will be provided for each context.

Parameters

$contexts: A keyed array of all available contexts.

$required: The required context object or array of objects.

array|string $default: The default value for the select object, suitable for a #default_value render key. Where $required is an array, this is an array keyed by the same key values as $required for all keys where an empty string is not a suitable default. Otherwise it is just the default value.

Return value

array A form element, or NULL if there are no contexts that satisfy the requirements.

1 call to ctools_context_converter_selector()
views_content_views_content_type_edit_form in views_content/plugins/content_types/views.inc
Returns an edit form for a block.

File

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

Code

function ctools_context_converter_selector($contexts, $required, $default) {
  if (is_array($required)) {
    $result = array(
      '#tree' => TRUE,
    );
    $count = 1;
    foreach ($required as $id => $dependency) {
      $default_id = isset($default[$id]) ? $default[$id] : '';
      $result[] = _ctools_context_converter_selector($contexts, $dependency, $default_id, $count++);
    }
    return $result;
  }
  return _ctools_context_converter_selector($contexts, $required, $default);
}