function _webform_render_select in Webform 5.2
Same name and namespace in other branches
- 5 components/select.inc \_webform_render_select()
- 6.3 components/select.inc \_webform_render_select()
- 6.2 components/select.inc \_webform_render_select()
- 7.4 components/select.inc \_webform_render_select()
- 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 5 hack to correct default values.
$form_item['#process'] = array(
'webform_expand_checkboxes' => array(),
);
}
else {
// Set display as a radio set.
$form_item['#type'] = 'radios';
}
}
return $form_item;
}