checklistapi.api.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by the Checklist API module.
  5. */
  6. /**
  7. * @addtogroup hooks
  8. * @{
  9. */
  10. /**
  11. * Define all checklists provided by the module.
  12. *
  13. * Any number of checklists can be defined in an implementation of this hook.
  14. * Checklist API will register menu items and create permissions for each one.
  15. *
  16. * @return array
  17. * An array of checklist definitions. Each definition is keyed by an arbitrary
  18. * unique identifier. The corresponding multidimensional array describing the
  19. * checklist may contain the following key-value pairs:
  20. * - #title: The title of the checklist.
  21. * - #path: The Drupal path where the checklist will be accessed.
  22. * - #description: (optional) A brief description of the checklist for its
  23. * corresponding menu item.
  24. * - #help: (optional) User help to be displayed in the "System help" block
  25. * via hook_help().
  26. * - #menu_name: (optional) The machine name of a menu to place the checklist
  27. * into (e.g. "main-menu" or "navigation"). If this is omitted, Drupal will
  28. * try to infer the correct menu placement from the specified path.
  29. * - #weight: (optional) A floating point number used to sort the list of
  30. * checklists before being output. Lower numbers appear before higher
  31. * numbers.
  32. * - Any number of arrays representing groups of items, to be presented as
  33. * vertical tabs. Each group is keyed by an arbitrary identifier, unique in
  34. * the scope of the checklist. The corresponding multimensional array
  35. * describing the group may contain the following key-value pairs:
  36. * - #title: The title of the group, used as the vertical tab label.
  37. * - #description: (optional) A description of the group.
  38. * - #weight: (optional) A floating point number used to sort the list of
  39. * groups before being output. Lower numbers appear before higher numbers.
  40. * - Any number of arrays representing checklist items. Each item is keyed
  41. * by an arbitrary identifier, unique in the scope of the checklist. The
  42. * corresponding multimensional array describing the item may contain the
  43. * following key-value pairs:
  44. * - #title: The title of the item.
  45. * - #description: (optional) A description of the item, for display
  46. * beneath the title.
  47. * - #default_value: (optional) The default checked state of the
  48. * item--TRUE for checked or FALSE for unchecked. Defaults to FALSE.
  49. * This is useful for automatically checking items that can be
  50. * programmatically tested (e.g. a module is installed or a variable has
  51. * a certain value).
  52. * - #weight: (optional) A floating point number used to sort the list of
  53. * items before being output. Lower numbers appear before higher
  54. * numbers.
  55. * - Any number of arrays representing links. Each link is keyed by an
  56. * arbitrary unique identifier. The corresponding multimensional array
  57. * describing the link may contain the following key-value pairs:
  58. * - #text: The link text.
  59. * - #path: The link path.
  60. * - #options: (optional) An associative array of additional options
  61. * used by the l() function.
  62. * - #weight: (optional) A floating point number used to sort the list
  63. * of items before being output. Lower numbers appear before higher
  64. * numbers.
  65. *
  66. * For a working example, see checklistapi_example.module.
  67. *
  68. * @see checklistapi_example_checklistapi_checklist_info()
  69. * @see hook_checklistapi_checklist_info_alter()
  70. */
  71. function hook_checklistapi_checklist_info() {
  72. $definitions = array();
  73. $definitions['example_checklist'] = array(
  74. '#title' => t('Example checklist'),
  75. '#path' => 'example-checklist',
  76. '#description' => t('An example checklist.'),
  77. '#help' => t('<p>This is an example checklist.</p>'),
  78. 'example_group' => array(
  79. '#title' => t('Example group'),
  80. '#description' => t('<p>Here are some example items.</p>'),
  81. 'example_item_1' => array(
  82. '#title' => t('Example item 1'),
  83. 'example_link' => array(
  84. '#text' => t('Example.com'),
  85. '#path' => 'http://www.example.com/',
  86. ),
  87. ),
  88. 'example_item_2' => array(
  89. '#title' => t('Example item 2'),
  90. ),
  91. ),
  92. );
  93. return $definitions;
  94. }
  95. /**
  96. * Alter checklist definitions.
  97. *
  98. * This hook is invoked by checklistapi_get_checklist_info(). The checklist
  99. * definitions are passed in by reference. Additional checklists may be added,
  100. * or existing checklists may be altered or removed.
  101. *
  102. * @param array $definitions
  103. * The multidimensional array of checklist definitions returned by
  104. * hook_checklistapi_checklist_info().
  105. *
  106. * For a working example, see checklistapi_example.module.
  107. *
  108. * @see checklistapi_get_checklist_info()
  109. * @see hook_checklistapi_checklist_info()
  110. */
  111. function hook_checklistapi_checklist_info_alter(array &$definitions) {
  112. // Add an item.
  113. $definitions['example_checklist']['example_group']['new_item'] = array(
  114. 'title' => t('New item'),
  115. );
  116. // Add a group.
  117. $definitions['example_checklist']['new_group'] = array(
  118. '#title' => t('New group'),
  119. );
  120. // Move an item.
  121. $definitions['example_checklist']['new_group']['example_item_1'] = $definitions['example_checklist']['example_group']['example_item_1'];
  122. unset($definitions['example_checklist']['example_group']['example_item_1']);
  123. // Remove an item.
  124. unset($definitions['example_checklist']['example_group']['example_item_2']);
  125. }
  126. /**
  127. * @} End of "addtogroup hooks".
  128. */