1 admin_bar.inc | admin_bar_output($complete = FALSE) |
Build the administration bar output.
Parameters
bool $complete: (optional) Whether to build to the complete menu including all components and ignore the cache. Defaults to FALSE. Internally used for the settings page.
File
- core/
modules/ admin_bar/ admin_bar.inc, line 15 - Menu builder functions for Administration bar.
Code
function admin_bar_output($complete = FALSE) {
global $user, $language;
$config = config('admin_bar.settings');
$cache_server_enabled = !$complete;
$cid = 'admin_bar:' . $user->uid . ':' . session_id() . ':' . $language->langcode;
// Try to load and output administration bar from server-side cache. The
// cache is only valid if a hash key exists, otherwise it needs to be
// regenerated.
$old_hash = admin_bar_cache_get($cid);
if ($cache_server_enabled && $old_hash) {
$cache = cache('menu')->get($cid);
if ($cache && isset($cache->data)) {
$content = $cache->data;
}
}
// Rebuild the output.
if (!isset($content)) {
// Retrieve enabled components to display and make them available for others.
$components = $config->get('components');
$content['#components'] = $components;
$content['#complete'] = $complete;
// Add site name as CSS class for development/staging purposes. We leverage
// the cookie domain instead of HTTP_HOST to account for many (but not all)
// multi-domain setups (e.g. language-based sub-domains).
$classes = 'admin-bar-site' . backdrop_strtolower(preg_replace('/[^a-zA-Z0-9-]/', '-', $GLOBALS['cookie_domain']));
// @todo Always output container to harden JS-less support.
$content['#prefix'] = '<div id="admin-bar" class="' . $classes . '"><div id="admin-bar-wrapper">';
$content['#suffix'] = '</div></div>';
// Add administration bar.
if (in_array('admin_bar.menu', $components) || $complete) {
$content['menu'] = array(
'#theme' => 'admin_bar_links',
'#wrapper_attributes' => array(
'id' => 'admin-bar-menu',
),
'#weight' => 0,
'#level' => -1,
);
$content['menu']['menu'] = admin_bar_links_menu(admin_bar_tree('management'));
$content['menu']['menu']['#title'] = t('Admin bar');
$content['menu']['menu']['#options']['icon'] = 'list';
}
// Check for status report errors.
if (user_access('administer site configuration')) {
$content['alert'] = admin_bar_links_alert();
}
// Add menu additions.
$content['extra']['extra'] = array();
if (in_array('admin_bar.icon', $components) || $complete) {
$content['icon'] = admin_bar_links_icon();
}
if (in_array('admin_bar.search', $components) || $complete) {
$content['extra']['extra'] += admin_bar_links_search();
}
if (in_array('admin_bar.locale', $components) || $complete) {
$content['extra']['extra'] += admin_bar_links_locale();
}
if (in_array('admin_bar.page', $components) || $complete) {
$content['extra']['extra'] += admin_bar_links_page();
}
if (in_array('admin_bar.account', $components) || $complete) {
$content['extra']['extra'] += admin_bar_links_account();
}
if (in_array('admin_bar.users', $components) || $complete) {
$content['extra']['extra'] += admin_bar_links_users();
}
// Allow modules to enhance the menu.
// Uses '_output' suffix for consistency with the alter hook (see below).
foreach (module_implements('admin_bar_output_build') as $module) {
$function = $module . '_admin_bar_output_build';
$function($content);
}
if ($content['extra']['extra']) {
$content['extra']['#theme'] = 'admin_bar_links';
$content['extra']['#level'] = -1;
$content['extra']['extra']['#title'] = t('More tasks');
$content['extra']['extra']['#options']['icon'] = 'list-checks';
$content['extra']['#wrapper_attributes'] = array(
'id' => 'admin-bar-extra',
);
$content['extra']['#weight'] = 100;
}
// Allow modules to alter the output.
// The '_output' suffix is required to prevent hook implementation function
// name clashes with the contributed Admin module.
backdrop_alter('admin_bar_output', $content);
$content = backdrop_render($content);
// Cache the menu for this user.
if ($cache_server_enabled) {
cache('menu')->set($cid, $content);
}
}
// Store the new hash for this user.
if (!$complete) {
admin_bar_cache_set($cid, md5($content));
}
return $content;
}