admin_menu.api.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /**
  3. * @file
  4. * API documentation for Administration menu.
  5. */
  6. /**
  7. * Provide expansion arguments for dynamic menu items.
  8. *
  9. * The map items must be keyed by the dynamic path to expand, i.e. a menu path
  10. * containing one or more '%' placeholders. Each map item may have the following
  11. * properties:
  12. * - parent: The parent menu path to link the expanded items to.
  13. * - arguments: An array of argument sets that will be used in the expansion.
  14. * Each set consists of an array of one or more placeholders, which again is
  15. * an array of possible expansion values. Upon expansion, each argument is
  16. * combined with every other argument from the set (technically, the cartesian
  17. * product of all arguments). The expansion values may be empty; that is, you
  18. * do not need to insert logic to skip map items for which no values exist,
  19. * since Administration menu will take care of that.
  20. *
  21. * @see admin_menu.map.inc
  22. */
  23. function hook_admin_menu_map() {
  24. // Expand content types below Structure > Content types.
  25. // The key denotes the dynamic path to expand to multiple menu items.
  26. $map['admin/structure/types/manage/%node_type'] = array(
  27. // Link generated items directly to the "Content types" item.
  28. 'parent' => 'admin/structure/types',
  29. // Create expansion arguments for the '%node_type' placeholder.
  30. 'arguments' => array(
  31. array(
  32. '%node_type' => array_keys(node_type_get_types()),
  33. ),
  34. ),
  35. );
  36. return $map;
  37. }
  38. /**
  39. * Add to the administration menu content before it is rendered.
  40. *
  41. * Only use this hook to add new data to the menu structure. Use
  42. * hook_admin_menu_output_alter() to *alter* existing data.
  43. *
  44. * @param array $content
  45. * A structured array suitable for drupal_render(), potentially containing:
  46. * - menu: The administrative menu of links below the path 'admin/*'.
  47. * - icon: The icon menu.
  48. * - account: The user account name and log out link.
  49. * - users: The user counter.
  50. * Additionally, these special properties:
  51. * - #components: The actual components contained in $content are configurable
  52. * and depend on the 'admin_menu_components' configuration value. #components
  53. * holds a copy of that for convenience.
  54. * - #complete: A Boolean indicating whether the complete menu should be built,
  55. * ignoring the current configuration in #components.
  56. * Passed by reference.
  57. *
  58. * @see hook_admin_menu_output_alter()
  59. * @see admin_menu_links_menu()
  60. * @see admin_menu_links_icon()
  61. * @see admin_menu_links_user()
  62. * @see theme_admin_menu_links()
  63. */
  64. function hook_admin_menu_output_build(&$content) {
  65. // In case your implementation provides a configurable component, check
  66. // whether the component should be displayed:
  67. if (empty($content['#components']['shortcut.links']) && !$content['#complete']) {
  68. return;
  69. }
  70. // Add new top-level item to the menu.
  71. if (isset($content['menu'])) {
  72. $content['menu']['myitem'] = array(
  73. '#title' => t('My item'),
  74. // #attributes are used for list items (LI).
  75. '#attributes' => array('class' => array('mymodule-myitem')),
  76. '#href' => 'mymodule/path',
  77. // #options are passed to l().
  78. '#options' => array(
  79. 'query' => drupal_get_destination(),
  80. // Apply a class on the link (anchor).
  81. 'attributes' => array('class' => array('myitem-link-anchor')),
  82. ),
  83. // #weight controls the order of links in the resulting item list.
  84. '#weight' => 50,
  85. );
  86. }
  87. // Add link to the icon menu to manually run cron.
  88. if (isset($content['icon'])) {
  89. $content['icon']['myitem']['cron'] = array(
  90. '#title' => t('Run cron'),
  91. '#access' => user_access('administer site configuration'),
  92. '#href' => 'admin/reports/status/run-cron',
  93. );
  94. }
  95. }
  96. /**
  97. * Change the administration menu content before it is rendered.
  98. *
  99. * Only use this hook to alter existing data in the menu structure. Use
  100. * hook_admin_menu_output_build() to *add* new data.
  101. *
  102. * @param array $content
  103. * A structured array suitable for drupal_render(). Passed by reference.
  104. *
  105. * @see hook_admin_menu_output_build()
  106. */
  107. function hook_admin_menu_output_alter(&$content) {
  108. }
  109. /**
  110. * Return content to be replace via JS in the cached menu output.
  111. *
  112. * @param bool $complete
  113. * A Boolean indicating whether all available components of the menu will be
  114. * output and the cache will be skipped.
  115. *
  116. * @return array
  117. * An associative array whose keys are jQuery selectors and whose values are
  118. * strings containing the replacement content.
  119. */
  120. function hook_admin_menu_replacements($complete) {
  121. $items = array();
  122. // If the complete menu is output, then it is uncached and will contain the
  123. // current counts already.
  124. if (!$complete) {
  125. // Check whether the users count component is enabled.
  126. $components = variable_get('admin_menu_components', array());
  127. if (!empty($components['admin_menu.users']) && ($user_count = admin_menu_get_user_count())) {
  128. // Replace the counters in the cached menu output with current counts.
  129. $items['.admin-menu-users a'] = $user_count;
  130. }
  131. }
  132. return $items;
  133. }
  134. /**
  135. * Inform about additional module-specific caches that can be cleared.
  136. *
  137. * Administration menu uses this hook to gather information about available
  138. * caches that can be flushed individually. Each returned item forms a separate
  139. * menu link below the "Flush all caches" link in the icon menu.
  140. *
  141. * @return array
  142. * An associative array whose keys denote internal identifiers for a
  143. * particular caches (which can be freely defined, but should be in a module's
  144. * namespace) and whose values are associative arrays containing:
  145. * - title: The name of the cache, without "cache" suffix. This label is
  146. * output as link text, but also for the "!title cache cleared."
  147. * confirmation message after flushing the cache; make sure it works and
  148. * makes sense to users in both locations.
  149. * - callback: The name of a function to invoke to flush the individual cache.
  150. */
  151. function hook_admin_menu_cache_info() {
  152. $caches['update'] = array(
  153. 'title' => t('Update data'),
  154. 'callback' => '_update_cache_clear',
  155. );
  156. return $caches;
  157. }