diff -u b/admin_menu.inc b/admin_menu.inc --- b/admin_menu.inc +++ b/admin_menu.inc @@ -1,5 +1,6 @@ t('Run cron'), '#weight' => 50, - '#access' => user_access('administer site configuration'), + '#access' => \Drupal::currentUser()->hasPermission('administer site configuration'), '#href' => 'admin/reports/status/run-cron', '#options' => array( 'query' => $destination, @@ -451,7 +452,7 @@ '#title' => t('Run updates'), '#weight' => 50, // @see update_access_allowed() - '#access' => $GLOBALS['user']->uid == 1 || !empty($GLOBALS['update_free_access']) || user_access('administer software updates'), + '#access' => $GLOBALS['user']->uid == 1 || !empty($GLOBALS['update_free_access']) || \Drupal::currentUser()->hasPermission('administer software updates'), '#href' => base_path() . 'update.php', '#options' => array( 'external' => TRUE, @@ -461,12 +462,12 @@ $links['icon']['drupal.org'] = array( '#title' => 'Drupal.org', '#weight' => 100, - '#access' => user_access('display drupal links'), + '#access' => \Drupal::currentUser()->hasPermission('display drupal links'), '#href' => 'http://drupal.org', ); // Add links to project issue queues. - foreach (module_list() as $module) { - $info = drupal_parse_info_file(drupal_get_path('module', $module) . '/' . $module . '.info.yml'); + foreach (\Drupal::moduleHandler()->getModuleList() as $module_name => $module) { + $info = drupal_parse_info_file($module->getPath() . '/' . $module_name . '.info.yml'); if (!isset($info['project']) || isset($links['icon']['drupal.org'][$info['project']])) { continue; } @@ -483,7 +484,7 @@ $links['icon']['flush-cache'] = array( '#title' => t('Flush all caches'), '#weight' => 20, - '#access' => user_access('flush caches'), + '#access' => \Drupal::currentUser()->hasPermission('flush caches'), '#href' => 'admin_menu/flush-cache', '#options' => array( 'query' => $destination + array('token' => drupal_get_token('admin_menu/flush-cache')), @@ -501,10 +502,10 @@ } // Add Devel module menu links. - if (module_exists('devel')) { + if (\Drupal::moduleHandler()->moduleExists('devel')) { $devel_tree = menu_build_tree('devel'); $devel_links = admin_menu_links_menu($devel_tree); - if (element_get_visible_children($devel_links)) { + if (Element::getVisibleChildren($devel_links)) { $links['icon']['devel'] = array( '#title' => t('Development'), '#weight' => 30, @@ -527,7 +528,7 @@ '#weight' => 100, ); $links['account'] = array( - '#title' => user_format_name($GLOBALS['user']), + '#title' => \Drupal::currentUser()->getUsername(), '#weight' => -99, '#attributes' => array('class' => array('admin-menu-action', 'admin-menu-account')), '#href' => 'user/' . $GLOBALS['user']->uid, @@ -539,8 +540,8 @@ '#href' => 'user/logout', ); // Add Devel module switch user links. - if (!module_exists('masquerade')) { - $switch_links = module_invoke('devel', 'switch_user_list'); + if (!\Drupal::moduleHandler()->moduleExists('masquerade')) { + $switch_links = \Drupal::moduleHandler()->invoke('devel', 'switch_user_list'); if (!empty($switch_links) && count($switch_links) > 1) { foreach ($switch_links as $uid => $link) { $links['account'][$uid] = array( @@ -575,7 +576,7 @@ '#description' => t('Current anonymous / authenticated users'), '#weight' => -90, '#attributes' => array('class' => array('admin-menu-action', 'admin-menu-users')), - '#href' => (user_access('administer users') ? 'admin/people/people' : 'user'), + '#href' => (\Drupal::currentUser()->hasPermission('administer users') ? 'admin/people/people' : 'user'), ); return $links; } @@ -853,14 +854,14 @@ break; case 'bootstrap': - cache('bootstrap')->deleteAll(); - cache('config')->deleteAll(); + \Drupal::cache('bootstrap')->deleteAll(); + \Drupal::cache('config')->deleteAll(); break; case 'cache': // @see drupal_flush_all_caches() foreach (\Drupal::moduleHandler()->invokeAll('cache_flush') as $bin) { - cache($bin)->deleteAll(); + \Drupal::cache($bin)->deleteAll(); } break; @@ -868,16 +869,16 @@ // Change query-strings on css/js files to enforce reload for all users. _drupal_flush_css_js(); - drupal_clear_css_cache(); - drupal_clear_js_cache(); + \Drupal::service('asset.css.collection_optimizer')->deleteAll(); + \Drupal::service('asset.js.collection_optimizer')->deleteAll(); // Clear the page cache, since cached HTML pages might link to old CSS and // JS aggregates. - cache('page')->deleteAll(); + \Drupal::cache('page')->deleteAll(); break; case 'theme': - system_rebuild_theme_data(); + \Drupal::service('theme_handler')->rebuildThemeData(); drupal_theme_rebuild(); break; } diff -u b/admin_menu.module b/admin_menu.module --- b/admin_menu.module +++ b/admin_menu.module @@ -173,27 +173,14 @@ * Implements hook_page_bottom(). */ function admin_menu_page_bottom(array &$page_bottom) { - if (!\Drupal::currentUser()->hasPermission('access administration menu')) { - return; - } - - if (admin_menu_suppress(FALSE)) { - $page_bottom['admin_menu_suppress'] = [ - '#attached' => [ - 'drupalSettings' => [ - 'admin_menu' => ['suppress' => 1], - ], - ], - ]; + if (!user_access('access administration menu') || admin_menu_suppress(FALSE)) { return; } - - // Performance: Skip this entirely for non-HTML requests. - $request_format = \Drupal::service('request_stack')->getCurrentRequest()->getRequestFormat(); - if ($request_format != 'html') { + // Performance: Skip this entirely for AJAX requests. + $current_path = current_path(); + if (strpos($current_path, 'js/') === 0) { return; } - global $user; $path = drupal_get_path('module', 'admin_menu'); @@ -219,14 +206,27 @@ * Implements hook_page_bottom(). */ function admin_menu_page_bottom(array &$page_bottom) { - if (!user_access('access administration menu') || admin_menu_suppress(FALSE)) { + if (!\Drupal::currentUser()->hasPermission('access administration menu')) { return; } - // Performance: Skip this entirely for AJAX requests. - $current_path = current_path(); - if (strpos($current_path, 'js/') === 0) { + + if (admin_menu_suppress(FALSE)) { + $page_bottom['admin_menu_suppress'] = [ + '#attached' => [ + 'drupalSettings' => [ + 'admin_menu' => ['suppress' => 1], + ], + ], + ]; + return; + } + + // Performance: Skip this entirely for non-HTML requests. + $request_format = \Drupal::service('request_stack')->getCurrentRequest()->getRequestFormat(); + if ($request_format != 'html') { return; } + global $user; $path = drupal_get_path('module', 'admin_menu'); only in patch2: unchanged: --- a/admin_menu.api.php +++ b/admin_menu.api.php @@ -92,7 +92,7 @@ function hook_admin_menu_output_build(&$content) { if (isset($content['icon'])) { $content['icon']['myitem']['cron'] = array( '#title' => t('Run cron'), - '#access' => user_access('administer site configuration'), + '#access' => \Drupal::currentUser()->hasPermission('administer site configuration'), '#href' => 'admin/reports/status/run-cron', ); }