You are here

function _webform_render_select in Webform 6.2

Same name and namespace in other branches
  1. 5.2 components/select.inc \_webform_render_select()
  2. 5 components/select.inc \_webform_render_select()
  3. 6.3 components/select.inc \_webform_render_select()
  4. 7.4 components/select.inc \_webform_render_select()
  5. 7.3 components/select.inc \_webform_render_select()

Build a form item array containing all the properties of this component.

Parameters

$component: An array of information describing the component, directly correlating to the webform_component database schema.

Return value

An array of a form item to be displayed on the client-side webform.

1 call to _webform_render_select()
_webform_submission_display_select in components/select.inc
Display the result of a textfield submission. The output of this function will be displayed under the "results" tab then "submissions".

File

components/select.inc, line 139
Webform module multiple select component.

Code

function _webform_render_select($component) {
  $form_item = array(
    '#title' => $component['name'],
    '#required' => $component['mandatory'],
    '#weight' => $component['weight'],
    '#description' => _webform_filter_descriptions($component['extra']['description']),
    '#prefix' => '<div class="webform-component-' . $component['type'] . '" id="webform-component-' . $component['form_key'] . '">',
    '#suffix' => '</div>',
  );

  // Convert the user-entered options list into an array.
  $default_value = _webform_filter_values($component['value'], NULL, NULL, FALSE);
  $options = _webform_select_options($component['extra']['items'], $component['extra']['aslist'] !== 'Y');
  if ($component['extra']['aslist'] === 'Y' && $component['extra']['multiple'] !== 'Y' && !($component['mandatory'] && !empty($component['value']))) {
    $options = array(
      '' => t('select...'),
    ) + $options;
  }

  // Set the component options.
  $form_item['#options'] = $options;

  // Set the default value.
  if ($default_value != '') {

    // Convert default value to a list if necessary.
    if ($component['extra']['multiple'] === 'Y') {
      $varray = array_filter(explode(',', $default_value));
      foreach ($varray as $key => $v) {
        $form_item['#default_value'][] = $v;
      }
    }
    else {
      $form_item['#default_value'] = $default_value;
    }
  }
  if ($component['extra']['aslist'] === 'Y') {

    // Set display as a select list:
    $form_item['#type'] = 'select';
    if ($component['extra']['multiple'] === 'Y') {
      $form_item['#multiple'] = TRUE;
    }
  }
  else {
    if ($component['extra']['multiple'] === 'Y') {

      // Set display as a checkbox set.
      $form_item['#type'] = 'checkboxes';

      // Drupal 6 hack to properly render on multipage forms.
      $form_item['#process'] = array(
        'webform_expand_checkboxes',
      );
    }
    else {

      // Set display as a radio set.
      $form_item['#type'] = 'radios';
    }
  }
  return $form_item;
}