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