function admin_menu_translated_menu_link_alter in Administration menu 6
Same name and namespace in other branches
- 8.3 admin_menu.module \admin_menu_translated_menu_link_alter()
- 6.3 admin_menu.module \admin_menu_translated_menu_link_alter()
- 7.3 admin_menu.module \admin_menu_translated_menu_link_alter()
Implementation of hook_translated_menu_link_alter().
Here is where we make changes to links that need dynamic information such as the current page path or the number of users.
File
- ./
admin_menu.module, line 256 - Renders a menu tree for administrative purposes as a dropdown menu at the top of the window.
Code
function admin_menu_translated_menu_link_alter(&$item, $map) {
global $user, $base_url;
static $access_all;
if (!isset($access_all)) {
// We only ever do this for development
$access_all = variable_get('admin_menu_show_all', 0) && module_exists('devel');
}
if ($item['menu_name'] != 'admin_menu') {
return;
}
if ($access_all && !$item['access']) {
$item['access'] = TRUE;
// Prepare for http://drupal.org/node/266596
if (!isset($item['localized_options'])) {
_menu_item_localize($item, $map, TRUE);
}
}
// We defined 'Run updates' as external link; apply proper base path now.
if ($item['link_path'] == 'update.php') {
$item['title'] = $item['link_title'];
$item['access'] = $user->uid == 1 || !empty($GLOBALS['update_free_access']);
$item['href'] = base_path() . $item['href'];
_menu_item_localize($item, $map, TRUE);
return;
}
// Don't waste cycles altering items that are not visible
if (!$item['access']) {
return;
}
if ($item['link_path'] == 'http://drupal.org' && !user_access('display drupal links')) {
$item['access'] = FALSE;
return;
}
// Fix destination query strings
if (isset($item['localized_options']['query'])) {
if ($item['localized_options']['query'] == 'destination') {
// URL token protects the link against CSRF attacks.
$item['localized_options']['query'] = drupal_get_destination() . '&token=' . drupal_get_token($item['link_path']);
}
}
if ($extra = variable_get('admin_menu_display', 0)) {
$item['title'] .= ' ' . $extra[0] . ': ' . $item[$extra];
}
// Handle items that need dynamic localization/replacement.
if (isset($item['options']['t'])) {
$item['title'] = t($item['title'], $item['options']['t'] + array(
'@username' => $user->name,
));
}
if ($item['title'] == 'icon_users') {
// Add count of active anonymous/authenticated users.
// @see user_block(), user.module
$interval = time() - variable_get('user_block_seconds_online', 900);
$count_anon = sess_count($interval);
$count_auth = db_result(db_query("SELECT COUNT(DISTINCT uid) FROM {sessions} WHERE uid > 0 AND timestamp >= %d", $interval));
$icon_users = '<img src="' . base_path() . drupal_get_path('module', 'admin_menu') . '/images/icon_users.png" width="16" height="15" alt="@title" title="@title" />';
$title = array(
'@title' => t('Current anonymous / authenticated users'),
);
$icon_users = strtr($icon_users, $title);
$item['title'] = t('@count-anon / @count-auth !icon', array(
'@count-anon' => $count_anon,
'@count-auth' => $count_auth,
'!icon' => $icon_users,
));
if (user_access('administer users')) {
$item['href'] = 'admin/user/user';
}
}
}