function admin_menu_page_bottom in Administration menu 8.3
Implements hook_page_bottom().
File
- ./
admin_menu.module, line 151 - Render an administrative menu as a dropdown menu at the top of the window.
Code
function admin_menu_page_bottom(array &$page_bottom) {
if (!\Drupal::currentUser()
->hasPermission('access administration menu') || admin_menu_suppress(FALSE)) {
return;
}
// Performance: Skip this entirely for AJAX requests.
$current_path = \Drupal::request()
->getRequestUri();
if (strpos($current_path, 'js/') === 0) {
return;
}
global $user;
$page_bottom['admin_menu'] = [
'#attached' => [
'library' => [
'admin_menu/drupal.admin_menu',
],
],
];
$attached =& $page_bottom['admin_menu']['#attached'];
// @todo D8: every_page is broken for System libraries.
// @see http://drupal.org/node/1805452
// @codingStandardsIgnoreLine
$options = [
'every_page' => TRUE,
];
$options = [];
if ($user->uid == 1) {
$attached['library'][] = 'admin_menu/drupal.admin_menu_uid1';
}
// Destination query strings are applied via JS.
$settings['destination'] = drupal_http_build_query(drupal_get_destination());
// Determine whether we need to show all components and disable all caches.
$complete = FALSE;
if (\Drupal::request()
->getRequestUri() == 'admin/config/admin/admin_menu' && $_SERVER['REQUEST_METHOD'] == 'GET') {
$complete = TRUE;
}
// If the client supports JavaScript and we have a cached menu for the current
// user, only output the hash for the client-side HTTP cache callback URL.
$cid = 'admin_menu:' . $user->uid . ':' . session_id() . ':' . language(LANGUAGE_TYPE_INTERFACE)->langcode;
if (!$complete && ($hash = admin_menu_cache_get($cid))) {
$settings['hash'] = $hash;
// The base path to use for cache requests depends on whether clean URLs
// are enabled, whether Drupal runs in a sub-directory, and on the language
// system configuration. url() already provides us the proper path and also
// invokes potentially existing custom_url_rewrite() functions, which may
// add further required components to the URL to provide context. Due to
// those components, and since url('') returns only base_path() when clean
// URLs are disabled, we need to use a replacement token as path. Yuck.
$settings['basePath'] = url('admin_menu');
}
else {
$page_bottom['admin_menu']['#markup'] = admin_menu_output($complete);
}
$replacements = module_invoke_all('admin_menu_replacements', $complete);
if (!empty($replacements)) {
$settings['replacements'] = $replacements;
}
if ($setting = variable_get('admin_menu_margin_top', 1)) {
$settings['margin_top'] = $setting;
// @todo Drupal.behaviors.adminMenuMarginTop is obsolete, but
// hook_page_build() does not allow to set a CSS class on the body yet.
// @see http://drupal.org/node/1473548, http://drupal.org/node/1194528
//$page['#attributes']['class'][] = 'admin-menu';
}
if ($setting = variable_get('admin_menu_position_fixed', 1)) {
$settings['position_fixed'] = $setting;
// TODO: does this still apply on D8?
// In fixed positioning, supply a callback function for tableheader.js to
// allow it to determine the top viewport offset.
// @see admin_menu.js, toolbar.js
/*
$attached['js'][] = array(
'data' => array('tableHeaderOffset' => 'Drupal.admin.height'),
'type' => 'setting',
);
*/
}
if ($setting = variable_get('admin_menu_tweak_tabs', 0)) {
$settings['tweak_tabs'] = $setting;
}
if ($current_path == 'admin/modules' || strpos($current_path, 'admin/modules/list') === 0) {
$settings['tweak_modules'] = variable_get('admin_menu_tweak_modules', 0);
}
if ($current_path == 'admin/people/permissions' || $current_path == 'admin/people/permissions/list') {
$settings['tweak_permissions'] = variable_get('admin_menu_tweak_permissions', 0);
}
$attached['drupalSettings']['admin_menu']['settings'] = $settings;
}