You are here

function _ctools_context_selector in Chaos Tool Suite (ctools) 6

Same name and namespace in other branches
  1. 7 includes/context.inc \_ctools_context_selector()
1 call to _ctools_context_selector()
ctools_context_selector in includes/context.inc
Create a select box to choose possible contexts.

File

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

Code

function _ctools_context_selector($contexts, $required, $default, $num = 0) {
  $filtered = ctools_context_filter($contexts, $required);
  $count = count($filtered);
  $form = array();
  if ($count >= 1) {

    // If there's more than one to choose from, create a select widget.
    foreach ($filtered as $cid => $context) {
      $options[$cid] = $context
        ->get_identifier();
    }
    if (!empty($required->title)) {
      $title = $required->title;
    }
    else {
      $title = $num ? t('Context %count', array(
        '%count' => $num,
      )) : t('Context');
    }
    return array(
      '#type' => 'select',
      '#options' => $options,
      '#title' => $title,
      '#default_value' => $default,
    );
  }
}