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