hs_flatlist.module 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * @file
  4. * Implementation of the Hierarchical Select API that allows one to use
  5. * Hierarchical Select's dropbox for selecting multiple items of a flat list.
  6. */
  7. //----------------------------------------------------------------------------
  8. // Hierarchical Select hooks.
  9. /**
  10. * Implements hook_hierarchical_select_params().
  11. */
  12. function hs_flatlist_hierarchical_select_params() {
  13. $params = array(
  14. 'options',
  15. );
  16. return $params;
  17. }
  18. /**
  19. * Implements hook_hierarchical_select_root_level().
  20. */
  21. function hs_flatlist_hierarchical_select_root_level($params) {
  22. return $params['options'];
  23. }
  24. /**
  25. * Implements hook_hierarchical_select_children().
  26. */
  27. function hs_flatlist_hierarchical_select_children($parent, $params) {
  28. return array(); // A flat list doesn't have any children, ever.
  29. }
  30. /**
  31. * Implements hook_hierarchical_select_lineage().
  32. */
  33. function hs_flatlist_hierarchical_select_lineage($item, $params) {
  34. return array($item); // No hierarchies exist in flat lists.
  35. }
  36. /**
  37. * Implements hook_hierarchical_select_valid_item().
  38. */
  39. function hs_flatlist_hierarchical_select_valid_item($item, $params) {
  40. return (in_array($item, array_keys($params['options'])));
  41. }
  42. /**
  43. * Implements hook_hierarchical_select_item_get_label().
  44. */
  45. function hs_flatlist_hierarchical_select_item_get_label($item, $params) {
  46. return $params['options'][$item];
  47. }
  48. /**
  49. * Implements hook_hierarchical_select_implementation_info().
  50. */
  51. function hs_flatlist_hierarchical_select_implementation_info() {
  52. return array(
  53. 'hierarchy type' => t('None: flat list'),
  54. 'entity type' => t('N/A'),
  55. );
  56. }