? .svn ? views_checkboxes-upgrade_to_d6-320800-8.patch Index: CHANGELOG.txt =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views_checkboxes/Attic/CHANGELOG.txt,v retrieving revision 1.1.2.6 diff -u -p -r1.1.2.6 CHANGELOG.txt --- CHANGELOG.txt 4 Jul 2008 00:27:21 -0000 1.1.2.6 +++ CHANGELOG.txt 15 Jan 2009 10:15:31 -0000 @@ -1,31 +1,36 @@ -Fri 04 Jul 2008 02:25:54 AM CEST +Fri 04 Jul 2008 02:25:54 AM CEST +================================== +- Small change to make it work with Views Filterblock module. -Small change to make it work with Views Filterblock module. -Sat 21 Jun 2008 02:27:26 CEST +Sat 21 Jun 2008 02:27:26 CEST +================================== +- Minor bug-fix, http://drupal.org/node/235873 -Minor bug-fix, http://drupal.org/node/235873 -Fri 13 Jun 2008 21:48:10 CEST - -No code changes - just tidying up to prepare for release. +Fri 13 Jun 2008 21:48:10 CEST +================================== +- No code changes - just tidying up to prepare for release. Mon 09 Jun 2008 02:30:45 CEST - -Bug fix for occasional errors/problems when using taxonomy terms - http://drupal.org/node/235873 - - -Mon 07 Apr 2008 20:04:43 CEST - -Just code tidying and tuning. No funcionality changes. +================================== +- Bug fix for occasional errors/problems when using taxonomy terms - http://drupal.org/node/235873 -Sun 06 Apr 2008 19:43:26 CEST +Mon 07 Apr 2008 20:04:43 CEST +================================== +- Just code tidying and tuning. No funcionality changes. -Removal of the "None selected" option in Taxonomy lists is now configurable. Uninstall updated to match. -When calculating number of items to check "limit", the "ALL" option, if present, is not counted. +Sun 06 Apr 2008 19:43:26 CEST +================================== +- Removal of the "None selected" option in Taxonomy lists is now configurable. Uninstall updated to match. +- When calculating number of items to check "limit", the "ALL" option, if present, is not counted. +- Added Id to files. Code layout tweaks. Minor structure changes to improve readability. -Added Id to files. Code layout tweaks. Minor structure changes to improve readability. +Wed 14 Jan 2009 12:00:00 GMT +================================== +- Upgrade to Drupal 6 +- Code restructure, added helper functions to perform core tasks Index: views_checkboxes.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views_checkboxes/views_checkboxes.info,v retrieving revision 1.3.6.2 diff -u -p -r1.3.6.2 views_checkboxes.info --- views_checkboxes.info 6 Apr 2008 11:37:02 -0000 1.3.6.2 +++ views_checkboxes.info 15 Jan 2009 10:15:31 -0000 @@ -1,5 +1,7 @@ +; $Id$ name = Views Checkboxes description = Views filter form modifications replace select boxes with checkboxes and radio buttons, as appropriate. package = Views -dependencies = views - +dependencies[] = views +core = 6.x +version = 6.x-4.0 Index: views_checkboxes.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views_checkboxes/views_checkboxes.module,v retrieving revision 1.8.2.11 diff -u -p -r1.8.2.11 views_checkboxes.module --- views_checkboxes.module 4 Jul 2008 00:27:21 -0000 1.8.2.11 +++ views_checkboxes.module 15 Jan 2009 10:15:31 -0000 @@ -1,11 +1,14 @@ Also, you can override the default size of select lists (the number of elements displayed).
'; - switch ($section) { + switch ($path) { case 'admin/help#views_checkboxes': $output .= 'Alters View filter forms to replace select elements wth checkboxes and radio buttons.
'; $output .= $new_features; @@ -18,22 +21,25 @@ function views_checkboxes_help($section= return $output; } +/** + * Implementation of hook_menu(). + */ 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'), + $items['admin/settings/views_checkboxes'] = array( + 'title' => 'Views checkboxes', + 'description' => 'Alter view filter forms', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('views_checkboxes_admin'), + 'access arguments' => array('administer views'), 'type' => MENU_NORMAL_ITEM ); return $items; } +/** + * Administration settings form. + */ function views_checkboxes_admin() { $form['views_checkboxes_checkbox_enable'] = array( '#type' => 'checkbox', @@ -82,80 +88,125 @@ function views_checkboxes_admin() { return system_settings_form($form); } -function views_checkboxes_form_alter($form_id, &$form) { +/** + * Implementation of hook_form_alter(). + */ +function views_checkboxes_form_alter(&$form, $form_state, $form_id) { + // views which have exposed filters get a $form_id of 'views_exposed_form' + // with views_Filterblock module installed, $form_id can be 'views_filterblock' + if ($form_id != 'views_exposed_form' && $form_id != 'views_filterblock') { + return; + } + + $limit = variable_get('views_checkboxes_limit', 5); - // Views which have exposed filters get a $form_id of 'views_filters' - // With Views_Filterblock module installed, $form_id can be 'views_filterblock' - if ($form_id != 'views_filters' && $form_id != 'views_filterblock') return; - - // Get configuration values... - $limit = variable_get('views_checkboxes_limit', 5); - $list_size = variable_get('views_checkboxes_listsize', FALSE); - $sizeup = variable_get('views_checkboxes_sizeup', FALSE); - $checkbox_enable = variable_get('views_checkboxes_checkbox_enable', FALSE); - $radio_enable = variable_get('views_checkboxes_radio_enable', FALSE); - $remove_none = variable_get('views_checkboxes_remove_none', FALSE); - - // Now loop through through all exposed filters... - foreach ($form['view']['#value']->exposed_filter as $count => $exposed) { - // ai: Set some references for use below (just for readability and maybe a little performance) - $this_filter = & $form['filter'.$count]; - $this_type = & $this_filter['#type']; $these_options = & $this_filter['#options']; - - // This is probably not necessary currently, but just in case Views module changes: - if ($this_type != 'select') continue; // Nothing useful to do so quick exit - - // Remove the "None selected" option which appears for "not required" Taxonomy terms: - if (isset($these_options['']) && $remove_none) unset($these_options['']); - - $list_count = count($these_options); // Get the number of options that will be listed - - // If enabled, use listsize setting: - if ($list_size) { - // increase listsize by one if enabled and appropriate - if ($sizeup && $list_size+1 == $list_count) ++$list_size; - $this_filter['#size'] = $list_size; + // now loop through through all form elements of the exposed filter form + foreach (element_children($form) as $form_element) { + // only operate on the select lists + if (!is_array($form[$form_element]) || $form[$form_element]['#type'] != 'select') { + continue; } - // If the number of options that would be displayed is greater than limit, use a listbox anyway. - if (isset($these_options['**ALL**'])) $list_count--; // Don't count "ALL" as it gets removed below - if ($list_count > $limit) continue; // Too many options, so use listbox - - // Check to see if we will have anything more to do and set up new types if so - switch ($exposed['single']) { - case 0: // Not single: use checkboxes - if (!$checkbox_enable) continue; // Not enabled, skip - $this_type = 'checkboxes'; // Set new type - break; - case 1: // Single: use radios - if (!$radio_enable) continue; // Not enabled, skip - $this_type = 'radios'; // Set new type - break; - default: - continue; // Neither (!?) so skip it anyway + // remove the "None selected" taxonomy option + views_checkboxes_remove_none_selected($form[$form_element]); + + // change the list size if required + $list_count = views_checkboxes_alter_list_size(&$form[$form_element]); + + // check the list size is not larger than the user-defined limit + if ($list_count > $limit) { + continue; } - // If we get this far, we are replacing the listbox with checkboxes/radios - // Need to unset the theme or else the views module will still make this a select box. - unset($this_filter['#theme']); - // Remove the "**ALL**" option if it exists: - if (isset($these_options['**ALL**'])) unset($these_options['**ALL**']); - - // Additional processing needed for taxonomy terms - they are an array of objects so need to be converted... - // NB: $these_options[0] can be '- None -' with 'optional' taxonomy terms, so we test [0] and [1] - if (is_object($these_options[1]) || is_object($these_options[0])) { - $newoptions = array(); - foreach ($these_options as $option_id => $option_obj) { - // Fix warning under rare circumstances, see http://drupal.org/node/235873 - if(!isset($option_obj->option)) continue; - foreach ($option_obj->option as $num => $val) { - $newoptions[$num] = $val; - } - } - // Set new options array back in the form. - $these_options = $newoptions; + // replace the selects with checkboxes/radios + views_checkboxes_replace_selects($form[$form_element]); + } +} + +/** + * Helper function that alters the number of options in the list + */ +function views_checkboxes_alter_list_size(&$form_element_obj) { + $list_size = variable_get('views_checkboxes_listsize', FALSE); + $sizeup = variable_get('views_checkboxes_sizeup', FALSE); + + // get the number of options that will be listed + $list_count = count($form_element_obj['#options']); + + // if the user has set a maximum list size, we alter the list + if ($list_size) { + // but first, we see if increasing the list size by 1 will allow us to + // include all options + if ($sizeup && $list_size + 1 == $list_count) { + ++$list_size; } + + // set the new size + $form_element_obj['#size'] = $list_size; + } + + // don't count "ALL" as it gets removed + if (isset($form_element_obj['#options']['**ALL**'])) { + $list_count--; } + + return $list_count; } -// --- End --- Drupal docs advise NOT closing the PHP tags. +/** + * Helper function that removes the "None selected" taxonomy option that + * appears for "not required" taxonomy terms. + */ +function views_checkboxes_remove_none_selected(&$form_element_obj) { + $remove_none = variable_get('views_checkboxes_remove_none', FALSE); + + if ($remove_none && isset($form_element_obj['#options'][''])) { + unset($form_element_obj['#options']['']); + } +} + +/** + * Helper function that handles the replacing of selects with checkboxes/radios + */ +function views_checkboxes_replace_selects(&$form_element_obj) { + $checkbox_enable = variable_get('views_checkboxes_checkbox_enable', FALSE); + $radio_enable = variable_get('views_checkboxes_radio_enable', FALSE); + + if (!$checkbox_enable && !$radio_enable) { + return; + } + + // make the changes to the form element #type, depending on settings + if ($checkbox_enable && $form_element_obj['#multiple']) { + $form_element_obj['#type'] = 'checkboxes'; + } + else if ($radio_enable && !$form_element_obj['#multiple']) { + $form_element_obj['#type'] = 'radios'; + } + + // need to unset the theme else the views module will make this a select box. + unset($form_element_obj['#theme']); + + // remove the "**ALL**" option if it exists: + if (isset($form_element_obj['#options']['**ALL**'])) { + unset($form_element_obj['#options']['**ALL**']); + } + + // additional processing needed for taxonomy terms - they are an array of objects so need to be converted... + // NB: $form_element_obj['#options'][0] can be '- None -' with 'optional' taxonomy terms, so we test [0] and [1] + if (is_object($form_element_obj['#options'][1]) || is_object($form_element_obj['#options'][0])) { + $newoptions = array(); + + foreach ($form_element_obj['#options'] as $option_id => $option_obj) { + // fix warning under rare circumstances, see http://drupal.org/node/235873 + if (!isset($option_obj->option)) { + continue; + } + foreach ($option_obj->option as $num => $val) { + $newoptions[$num] = $val; + } + } + // set new options array back in the form. + $form_element_obj['#options'] = $newoptions; + } +}