views_exposed_groups.module 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Implements hook_views_api().
  4. */
  5. function views_exposed_groups_views_api() {
  6. return array(
  7. 'api' => 3.0,
  8. );
  9. }
  10. /**
  11. * Implements hook_theme().
  12. */
  13. function views_exposed_groups_theme() {
  14. return array(
  15. 'views_exposed_groups_reorder_filter_form' => array(
  16. 'render element' => 'form',
  17. ),
  18. );
  19. }
  20. /**
  21. * Theme callback to render the option form as a draggable table.
  22. */
  23. function theme_views_exposed_groups_reorder_filter_form($vars) {
  24. $form = $vars['form'];
  25. $rows = array();
  26. foreach (element_children($form) as $key) {
  27. if (isset($form[$key]['weight'])) {
  28. $group = (is_numeric($form[$key]['group']['#default_value']))
  29. ? $form[$key]['group']['#default_value']
  30. : 0;
  31. $row = array();
  32. $row[] = $form[$key]['weight']['#title'];
  33. $form[$key]['weight']['#attributes']['class'] = array('weight', 'weight-'. $group);
  34. $form[$key]['group']['#attributes']['class'] = array('group-select', 'field-group-'. $group);
  35. $row[] = drupal_render($form[$key]['group']);
  36. $row[] = drupal_render($form[$key]['weight']);
  37. $class = array('draggable');
  38. $styles = array();
  39. $rows[$group][] = array('data' => $row, 'class' => $class, 'id' => 'display-row-' . $key, 'style' => $styles);
  40. }
  41. }
  42. $groups = explode("\n", $form['groups']['#default_value']);
  43. $table_rows = array();
  44. foreach($groups as $k => $group) {
  45. $table_rows[] = array(array('data' => '<strong>'. $group .'</strong>', 'colspan' => 3, 'attributes' => array('class' => array('field-group-header'))));
  46. foreach($rows[$k] as $row) {
  47. $table_rows[] = $row;
  48. }
  49. }
  50. foreach($groups as $k => $group) {
  51. drupal_add_tabledrag('reorder-group-filters', 'match', 'sibling', 'group-select', 'field-group-' . $k, NULL, FALSE);
  52. drupal_add_tabledrag('reorder-group-filters', 'order', 'sibling', 'weight', 'weight-' . $k);
  53. }
  54. $header = array(t('Filter'), t('Group'), t('Weight'));
  55. $output = '';
  56. $output = drupal_render($form['override']);
  57. $output .= theme('table',
  58. array('header' => $header,
  59. 'rows' => $table_rows,
  60. 'attributes' => array('id' => 'reorder-group-filters'),
  61. ));
  62. $output .= drupal_render_children($form);
  63. return $output;
  64. }