tabledrag_example.module 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * @file
  4. * An example of how to build a sortable form using tabledrag.
  5. */
  6. /**
  7. * @defgroup tabledrag_example Example: Tabledrag
  8. * @ingroup examples
  9. * @{
  10. * Example of draggable table rows.
  11. */
  12. /**
  13. * Implements hook_help().
  14. *
  15. * Show a bit of information about this module on the example page.
  16. */
  17. function tabledrag_example_help($path, $arg) {
  18. switch ($path) {
  19. case 'examples/tabledrag_example':
  20. return '<p>' . t('The form here is a themed as a table that is sortable using tabledrag handles.') . '</p>';
  21. }
  22. }
  23. /**
  24. * Implements hook_menu().
  25. *
  26. * We'll let drupal_get_form() generate the form page for us, for both of
  27. * these menu items.
  28. *
  29. * @see drupal_get_form()
  30. */
  31. function tabledrag_example_menu() {
  32. // Basic example with single-depth sorting.
  33. $items['examples/tabledrag_example_simple'] = array(
  34. 'title' => 'TableDrag example (simple)',
  35. 'description' => 'Show a page with a sortable tabledrag form',
  36. 'page callback' => 'drupal_get_form',
  37. 'page arguments' => array('tabledrag_example_simple_form'),
  38. 'access callback' => TRUE,
  39. 'file' => 'tabledrag_example_simple_form.inc',
  40. );
  41. // Basic parent/child example.
  42. $items['examples/tabledrag_example_parent'] = array(
  43. 'title' => 'TableDrag example (parent/child)',
  44. 'description' => 'Show a page with a sortable parent/child tabledrag form',
  45. 'page callback' => 'drupal_get_form',
  46. 'page arguments' => array('tabledrag_example_parent_form'),
  47. 'access callback' => TRUE,
  48. 'file' => 'tabledrag_example_parent_form.inc',
  49. );
  50. return $items;
  51. }
  52. /**
  53. * Implements hook_theme().
  54. *
  55. * We need run our forms through custom theme functions in order to build the
  56. * table structure which is required by tabledrag.js. Before we can use our
  57. * custom theme functions, we need to implement hook_theme in order to register
  58. * them with Drupal.
  59. *
  60. * We are defining our theme hooks with the same name as the form generation
  61. * function so that Drupal automatically calls our theming function when the
  62. * form is displayed.
  63. */
  64. function tabledrag_example_theme() {
  65. return array(
  66. // Theme function for the 'simple' example.
  67. 'tabledrag_example_simple_form' => array(
  68. 'render element' => 'form',
  69. 'file' => 'tabledrag_example_simple_form.inc',
  70. ),
  71. // Theme function for the 'parent/child' example.
  72. 'tabledrag_example_parent_form' => array(
  73. 'render element' => 'form',
  74. 'file' => 'tabledrag_example_parent_form.inc',
  75. ),
  76. );
  77. }
  78. /**
  79. * @} End of "defgroup tabledrag_example".
  80. */