You are here

function _ctools_context_converter_selector in Chaos Tool Suite (ctools) 6

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

File

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

Code

function _ctools_context_converter_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.
    $options = array();
    foreach ($filtered as $cid => $context) {
      if ($context->type == 'any') {
        $options[''] = t('No context');
        continue;
      }
      $key = $context
        ->get_identifier();
      if ($converters = ctools_context_get_converters($cid . '.', $context)) {
        $options[$key] = $converters;
      }
    }
    if (empty($options)) {
      return array(
        '#type' => 'value',
        '#value' => 'any',
      );
    }
    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,
      '#description' => t('Please choose which context and how you would like it converted.'),
      '#default_value' => $default,
    );
  }
}