function form_process_tableselect in Elements 6
Same name and namespace in other branches
- 5 elements.module \form_process_tableselect()
Create the correct amount of checkbox or radio elements to populate the table.
Parameters
$element: An associative array containing the properties and children of the tableselect element.
Return value
The processed element.
1 string reference to 'form_process_tableselect'
- elements_elements in ./
elements.module - Implements hook_elements().
File
- ./
elements.module, line 189
Code
function form_process_tableselect($element) {
if ($element['#multiple']) {
$value = is_array($element['#value']) ? $element['#value'] : array();
}
else {
// Advanced selection behaviour make no sense for radios.
$element['#js_select'] = FALSE;
}
$element['#tree'] = TRUE;
if (count($element['#options']) > 0) {
if (!isset($element['#default_value']) || $element['#default_value'] === 0) {
$element['#default_value'] = array();
}
// Create a checkbox or radio for each item in #options in such a way that
// the value of the tableselect element behaves as if it had been of type
// checkboxes or radios.
foreach ($element['#options'] as $key => $choice) {
// Do not overwrite manually created children.
if (!isset($element[$key])) {
if ($element['#multiple']) {
$element[$key] = array(
'#type' => 'checkbox',
'#title' => '',
'#return_value' => $key,
'#default_value' => isset($value[$key]),
'#attributes' => $element['#attributes'],
'#ahah' => isset($element['#ahah']) ? $element['#ahah'] : NULL,
);
}
else {
// Generate the parents as the autogenerator does, so we will have a
// unique id for each radio button.
$parents_for_id = array_merge($element['#parents'], array(
$key,
));
$element[$key] = array(
'#type' => 'radio',
'#title' => '',
'#return_value' => $key,
'#default_value' => $element['#default_value'] == $key ? $key : NULL,
'#attributes' => $element['#attributes'],
'#parents' => $element['#parents'],
'#id' => form_clean_id('edit-' . implode('-', $parents_for_id)),
'#ahah' => isset($element['#ahah']) ? $element['#ahah'] : NULL,
);
}
if (isset($element['#options'][$key]['#weight'])) {
$element[$key]['#weight'] = $element['#options'][$key]['#weight'];
}
}
}
}
else {
$element['#value'] = array();
}
return $element;
}