function ctools_context_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
array $contexts: A keyed array of all available contexts.
array|ctools_context_required|ctools_context_optional $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.
3 calls to ctools_context_selector()
- ctools_access_ajax_edit_item in includes/
context-access-admin.inc - Form to edit the settings of an access test.
- ctools_content_configure_form_defaults in includes/
content.inc - Add the default FAPI elements to the content type configuration form.
- ctools_edit_context_form_defaults in includes/
context-admin.inc - Form wrapper for the edit context form.
File
-
includes/
context.inc, line 568
Code
function ctools_context_selector($contexts, $required, $default) {
if (is_array($required)) {
$result = array(
'#tree' => TRUE,
);
$count = 1;
foreach ($required as $id => $item) {
$result[] = _ctools_context_selector($contexts, $item, isset($default[$id]) ? $default[$id] : '', $count++);
}
return $result;
}
return _ctools_context_selector($contexts, $required, $default);
}