Alters view filter forms to replace select elements wth checkboxes and radio buttons.

'; break; case 'admin/settings/views_checkboxes': $output .= '

Enable this module to replace all select form elements in view filters with checkboxes or radio buttons, as appropriate.

'; break; } return $output; } function views_checkboxes_menu() { $items = array(); $items[] = array( 'path' => 'admin/settings/views_checkboxes', 'title' => t('Views checkboxes'), 'description' => t('Alter view filter forms'), 'callback' => 'drupal_get_form', 'callback arguments' => 'views_checkboxes_admin', 'access' => user_access('administer views'), 'type' => MENU_NORMAL_ITEM ); return $items; } function views_checkboxes_admin() { $form['views_checkboxes_enable'] = array( '#type' => 'checkbox', '#title' => t('Alter View Filter Forms'), '#default_value' => variable_get('views_checkboxes_enable', FALSE), '#description' => t('Enable this module to replace all select form elements in view filters with checkboxes or radio buttons, as appropriate.'), ); return system_settings_form($form); } function views_checkboxes_form_alter($form_id, &$form) { if (!variable_get('views_checkboxes_enable', false)) { // default to disable this module return; } if (isset($form['view']['#value']->exposed_filter)) { // view filter forms don't seem to have a form_id, so I'm using this conditional to identify them. $view = $form['view']['#value']; foreach ($view->exposed_filter as $count => $exposed) { //Start looping through through all exposed filters $recreate_options = FALSE; if ($exposed['single'] == '1' && $form['filter'.$count]['#type'] == 'select') { // This is a select box with the single limitation. Should be radio buttons and need to unset // the theme or else the views module will still make this a select box. $form['filter'.$count]['#type'] = 'radios'; unset($form['filter'.$count]['#theme']); $recreate_options = TRUE; } if ($exposed['single'] == '0' && $form['filter'.$count]['#type'] == 'select') { // This is a select box with no single limitation. Should be checkboxes and need to unset // the theme or else the views module will still make this a select box. $form['filter'.$count]['#type'] = 'checkboxes'; unset($form['filter'.$count]['#theme']); $recreate_options = TRUE; } if ($recreate_options) { // The view options are an array of objects, instead of the typical array. This will recreate // them as a typical form option array. $newoptions = array(); foreach ($form['filter'.$count]['#options'] as $option_id => $option) { // I'm disabling the **ALL** option entirely, if it exists. if ($option_id == '**ALL**') continue; if (is_object($form['filter'.$count]['#options'][$option_id])) { foreach ($form['filter'.$count]['#options'][$option_id]->option as $num => $val) { $newoptions[$num] = $val; } } else { $newoptions[$option_id] = $option; } } $form['filter'.$count]['#options'] = $newoptions; } } } } ?>