function global_filter_create_simple_widget in Views Global Filter 8
Same name and namespace in other branches
- 7 widgets/global_filter.simplewidget.inc \global_filter_create_simple_widget()
Create simple widget.
2 calls to global_filter_create_simple_widget()
- global_filter_create_range_widget in widgets/
global_filter.rangewidget.inc - Create range widget.
- global_filter_create_widget in ./
global_filter.widgets.inc - Based on the requested or field-implied widget.
File
- widgets/
global_filter.simplewidget.inc, line 11 - global_filter.simplewidget.inc
Code
function global_filter_create_simple_widget($filter_key, $options, &$form, &$form_state) {
$name = $form_state['global_filters'][$filter_key]['name'];
$widget = $form_state['global_filters'][$filter_key]['widget'];
$default_value = isset($form_state['input'][$name]) ? $form_state['input'][$name] : global_filter_get_session_value($name);
if (is_array($default_value)) {
if ($widget == 'radios' || $widget == 'textfield') {
$default_value = reset($default_value);
}
}
else {
if ($widget == 'checkboxes') {
$default_value = array(
$default_value,
);
}
}
$form[$name] = array(
'#type' => $widget == 'multiselect' ? 'select' : $widget,
'#default_value' => $default_value,
// @todo: add description.
'#description' => NULL,
);
if ($widget == 'textfield') {
$form[$name]['#size'] = 20;
}
elseif (!empty($options)) {
$form[$name]['#options'] = $options;
$form[$name]['#multiple'] = in_array($widget, array(
'multiselect',
'checkboxes',
));
}
}