Skip to content

Instantly share code, notes, and snippets.

@quicksketch
Last active August 29, 2015 14:01
Show Gist options
  • Save quicksketch/fffaaa941a3f0ab926c8 to your computer and use it in GitHub Desktop.
Save quicksketch/fffaaa941a3f0ab926c8 to your computer and use it in GitHub Desktop.
Admin Menu Backdrop Port
diff --git a/admin_menu.admin.js b/admin_menu.admin.js
index 9ee9f36..fea1a54 100644
--- a/admin_menu.admin.js
+++ b/admin_menu.admin.js
@@ -5,7 +5,7 @@
*/
Drupal.behaviors.adminMenuLivePreview = {
attach: function (context, settings) {
- $('input[name^="admin_menu_components"]', context).once('admin-menu-live-preview')
+ $('input[name^="components"]', context).once('admin-menu-live-preview')
.change(function () {
var target = $(this).attr('rel');
$(target).toggle(this.checked);
@@ -45,7 +45,7 @@ Drupal.behaviors.adminMenuPermissionsSetupHelp = {
// Figure out which is the other, check whether it still disabled,
// and if so, ask whether to auto-enable it.
var other = (this == $admin[index] ? $menu[index] : $admin[index]);
- if (!other.checked && confirm(Drupal.t('Also allow !name role to !permission?', {
+ if (!other.checked && confirm(Drupal.t('Also allow !name role the "!permission" permission? This is usually required to display any pages within the administration menu.', {
'!name': $roles[index].textContent,
'!permission': (this == $admin[index] ? menuPermission : adminPermission)
}))) {
diff --git a/admin_menu.api.php b/admin_menu.api.php
index 2d212fb..3533f46 100644
--- a/admin_menu.api.php
+++ b/admin_menu.api.php
@@ -52,8 +52,8 @@ function hook_admin_menu_map() {
* - users: The user counter.
* Additionally, these special properties:
* - #components: The actual components contained in $content are configurable
- * and depend on the 'admin_menu_components' configuration value. #components
- * holds a copy of that for convenience.
+ * and depend on the 'admin_menu.settings.components' configuration value.
+ * #components holds a copy of that for convenience.
* - #complete: A Boolean indicating whether the complete menu should be built,
* ignoring the current configuration in #components.
* Passed by reference.
@@ -67,7 +67,7 @@ function hook_admin_menu_map() {
function hook_admin_menu_output_build(&$content) {
// In case your implementation provides a configurable component, check
// whether the component should be displayed:
- if (empty($content['#components']['shortcut.links']) && !$content['#complete']) {
+ if (in_array('shortcut.links', $content['#components']) && !$content['#complete']) {
return;
}
@@ -129,7 +129,7 @@ function hook_admin_menu_replacements($complete) {
// current counts already.
if (!$complete) {
// Check whether the users count component is enabled.
- $components = variable_get('admin_menu_components', array());
+ $components = config_get('admin_menu.settings', 'components');
if (!empty($components['admin_menu.users']) && ($user_count = admin_menu_get_user_count())) {
// Replace the counters in the cached menu output with current counts.
$items['.admin-menu-users a'] = $user_count;
diff --git a/admin_menu.css b/admin_menu.css
index b58a70e..8924d17 100644
--- a/admin_menu.css
+++ b/admin_menu.css
@@ -9,56 +9,85 @@
*/
#admin-menu {
- background: #101010 url(images/bkg.png) bottom left repeat-x;
- font-size: 9px;
- font-family: "lucida grande", tahoma, verdana, arial, sans-serif;
+ font: normal 11px "Lucida Grande", Verdana, sans-serif;
left: 0;
position: absolute;
- text-align: left;
+ text-align: left; /* LTR */
top: 0;
width: 100%;
+ line-height: 0;
+ padding: 0;
+ margin: 0;
+ background: #2D2D2D; /* Old browsers */
+ background: -moz-linear-gradient(#2D2D2D 0%, #171717 100%); /* FF3.6+ */
+ background: -webkit-gradient(color-stop(0%, #2D2D2D), color-stop(100%, #171717)); /* Chrome,Safari4+ */
+ background: -webkit-linear-gradient(#2D2D2D 0%, #171717 100%); /* Chrome10+,Safari5.1+ */
+ background: -o-linear-gradient(#2D2D2D 0%, #171717 100%); /* Opera 11.10+ */
+ background: -ms-linear-gradient(#2D2D2D 0%, #171717 100%); /* IE10+ */
+ background: linear-gradient(#2D2D2D 0%, #171717 100%); /* W3C */
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#2D2D2D', endColorstr='#171717',GradientType=0); /* IE6-9 */
+}
+[dir="rtl"] #admin-menu {
+ text-align: right;
}
#admin-menu-wrapper {
overflow: hidden;
}
-#admin-menu .dropdown .admin-menu-icon a {
- padding: 1px 8px 4px;
-}
-#admin-menu .dropdown .admin-menu-icon ul a {
- padding: 4px 8px;
-}
-#admin-menu .dropdown .admin-menu-icon img {
- vertical-align: bottom;
-}
-#admin-menu .dropdown .admin-menu-users a {
- background: transparent url(images/icon_users.png) 90% center no-repeat;
- padding-right: 22px;
+
+body.admin-menu {
+ margin-top: 30px !important;
}
-#admin-menu .dropdown .admin-menu-action,
-#admin-menu .dropdown .admin-menu-search {
- float: right;
+
+/* Top level items. */
+#admin-menu .top-level {
+ list-style: none;
+ margin: 0;
+ padding: 0;
+ display: inline-block;
}
-#admin-menu .dropdown .admin-menu-action a {
- border-left: 1px solid #323232;
- border-right: none;
+#admin-menu .top-level > li > a,
+#admin-menu .top-level > li > span {
+ display: none;
}
-body.admin-menu {
- margin-top: 20px !important;
+#admin-menu .top-level > li > ul {
+ display: inline-block;
+ left: auto;
+ width: auto;
+ right: auto;
+}
+#admin-menu .top-level > li > ul > li {
+ float: left;
+ width: auto;
+}
+#admin-menu-menu.top-level > li > ul > li > a.active-trail {
+ border-radius: 10px;
+ -moz-border-radius: 10px;
+ -webkit-border-radius: 10px;
+ padding: 4px 10px;
+ margin: 4px 2px;
+ text-shadow: #333 0 1px 0;
+ background: #9F9F9F; /* Old browsers */
+ background: -moz-linear-gradient(#9F9F9F 0%, #808080 100%); /* FF3.6+ */
+ background: -webkit-gradient(color-stop(0%, #9F9F9F), color-stop(100%, #808080)); /* Chrome,Safari4+ */
+ background: -webkit-linear-gradient(#9F9F9F 0%, #808080 100%); /* Chrome10+,Safari5.1+ */
+ background: -o-linear-gradient(#9F9F9F 0%, #808080 100%); /* Opera 11.10+ */
+ background: -ms-linear-gradient(#9F9F9F 0%, #808080 100%); /* IE10+ */
+ background: linear-gradient(#9F9F9F 0%, #808080 100%); /* W3C */
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#9F9F9F', endColorstr='#808080',GradientType=0); /* IE6-9 */
}
-/* All lists */
-#admin-menu,
+/* Dropdown lists */
#admin-menu .dropdown {
line-height: 1.4em;
list-style: none;
margin: 0;
padding: 0;
z-index: 999;
-}
-#admin-menu .dropdown {
+ display: inline-block;
position: static;
+ background: #202020;
}
-#admin-menu a,
+#admin-menu li > a,
#admin-menu li > span {
background: transparent none;
border: none;
@@ -67,21 +96,41 @@ body.admin-menu {
text-align: left; /* LTR */
text-decoration: none;
}
-#admin-menu .dropdown a,
+[dir="rtl"] #admin-menu li > a,
+[dir="rtl"] #admin-menu li > span {
+ text-align: right;
+}
+#admin-menu .dropdown li > a,
#admin-menu .dropdown li > span {
- border-right: 1px solid #323232; /* LTR */
display: block;
- padding: 4px 8px;
+ padding: 9px 12px;
+}
+
+#admin-menu a.expanded-trail,
+#admin-menu span.expanded-trail {
+ background: #45454A;
}
+
#admin-menu .dropdown .admin-menu-tab a {
+ border-left: none; /* LTR */
border-right: 1px solid #52565E; /* LTR */
}
+[dir="rtl"] #admin-menu .dropdown .admin-menu-tab a {
+ border-left: 1px solid #52565E;
+ border-right: none;
+}
#admin-menu .dropdown li li a {
border-right: none; /* LTR */
border-top: 1px solid #323232;
}
+[dir="rtl"] #admin-menu .dropdown li li a {
+ border-left: none;
+}
+#admin-menu .dropdown a:hover {
+ text-decoration: underline;
+}
-/* All list items */
+/* All dropdown list items */
#admin-menu .dropdown li {
background-image: none;
float: left; /* LTR */
@@ -91,14 +140,12 @@ body.admin-menu {
margin: 0 !important;
padding: 0;
}
-#admin-menu .dropdown .admin-menu-tab {
- background: url(images/bkg_tab.png) repeat-x left bottom;
- padding-bottom: 1px;
+[dir="rtl"] #admin-menu .dropdown li {
+ float: right;
}
+
+/* First level items */
#admin-menu .dropdown li li {
- background: #202020;
- filter: Alpha(opacity=88);
- opacity: 0.88;
width: 160px; /* Required for Opera */
}
#admin-menu .dropdown li li li {
@@ -109,7 +156,6 @@ body.admin-menu {
/* Second-level lists */
/* Note: We must hide sub-lists or scrollbars might appear (display: none is not read by screen readers). */
#admin-menu .dropdown li ul {
- background: none;
display: none;
left: -999em; /* LTR */
line-height: 1.2em;
@@ -117,77 +163,118 @@ body.admin-menu {
position: absolute;
width: 160px;
}
+[dir="rtl"] #admin-menu .dropdown li ul {
+ left: auto;
+ right: -999em;
+}
/* Third-and-above-level lists */
#admin-menu .dropdown li li.expandable ul {
- margin: -20px 0 0 160px; /* LTR */
+ margin: -32px 0 0 160px; /* LTR */
}
-
-#admin-menu .dropdown li:hover ul ul,
-#admin-menu .dropdown li:hover ul ul ul,
-#admin-menu .dropdown li:hover ul ul ul ul,
-#admin-menu .dropdown li:hover ul ul ul ul ul {
- display: none;
- left: -999em; /* LTR */
+[dir="rtl"] #admin-menu .dropdown li li.expandable ul {
+ margin-left: 160px;
+ margin-right: 0;
}
/* Lists nested under hovered list items */
-#admin-menu .dropdown li:hover ul,
-#admin-menu .dropdown li li:hover ul,
-#admin-menu .dropdown li li li:hover ul,
-#admin-menu .dropdown li li li li:hover ul,
-#admin-menu .dropdown li li li li li:hover ul {
+#admin-menu .dropdown ul.expanded {
display: block;
left: auto; /* LTR */
}
-#admin-menu .dropdown li.admin-menu-action:hover ul {
- right: 0; /* LTR */
+[dir="rtl"] #admin-menu .dropdown ul.expanded {
+ right: auto;
}
/* Second-and-more-level hovering */
-#admin-menu .dropdown li li.expandable {
- background: #45454A url(images/arrow.png) no-repeat 145px 6px;
-}
-#admin-menu .dropdown li li:hover {
- background-color: #111;
+#admin-menu .dropdown li li.expandable > a {
+ background: #45454A url(images/arrow.png) no-repeat 145px center; /* LTR */
}
-#admin-menu .dropdown li li:hover a,
-#admin-menu .dropdown li li:hover li:hover a,
-#admin-menu .dropdown li li:hover li:hover li:hover a {
- color: #FFF;
+[dir="rtl"] #admin-menu .dropdown li li.expandable > a {
+ background-image: url(images/arrow-rtl.png);
+ background-position: 5px center;
}
-#admin-menu .dropdown li li.expandable:hover a,
-#admin-menu .dropdown li li.expandable:hover li.expandable:hover a {
+#admin-menu .dropdown li li a.expanded-trail {
+ background-color: #111;
border-color: #444;
color: #EEE;
}
-#admin-menu .dropdown li li.expandable:hover li a,
-#admin-menu .dropdown li li.expandable:hover li.expandable:hover li a {
- border-color: #323232;
+
+/* Icon menu */
+#admin-menu-icon {
+ display: inline-block;
}
-#admin-menu .dropdown li li:hover li a {
- color: #EEE;
+#admin-menu-icon .admin-menu-icon > a {
+ padding: 7px 8px 8px;
+}
+#admin-menu-icon .admin-menu-icon img {
+ vertical-align: bottom;
+}
+
+/* Extras menu */
+#admin-menu-extra {
+ float: right; /* LTR */
+ direction: rtl; /* LTR */
+}
+[dir="rtl"] #admin-menu-extra {
+ float: left;
+ direction: ltr;
+}
+#admin-menu-extra .dropdown li {
+ direction: ltr; /* LTR */
+}[dir="rtl"] #admin-menu-extra .dropdown li {
+ direction: rtl;
+ }
+
+/* Online users */
+#admin-menu .dropdown .admin-menu-users a {
+ background: transparent url(images/icon_users.png) 90% center no-repeat;
+ padding-right: 22px; /* LTR */
+}
+[dir="rtl"] #admin-menu .dropdown .admin-menu-users a {
+ background-position: 10% center;
+ padding-left: 22px;
+ padding-right: 0;
+}
+
+#admin-menu .dropdown .admin-menu-action a {
+ border-left: 1px solid #323232;
+ border-right: none;
+}
+[dir="rtl"] #admin-menu .dropdown .admin-menu-action a {
+ border-left: none;
+ border-right: 1px solid #323232;
}
/* Search form */
#admin-menu .admin-menu-search .form-item {
margin: 0;
- padding: 0;
+ padding: 6px;
+ width: 92%;
+}
+#admin-menu .top-level .admin-menu-search {
+ width: 140px;
+}
+#admin-menu .top-level .admin-menu-search .form-item {
+ padding: 7px 0 0;
}
#admin-menu .admin-menu-search input {
background: #fff none center right no-repeat;
border: none;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
- border-radius: 5px;
- font-size: 10px;
- margin: 1px 0;
+ border-radius: 10px;
+ font-size: 12px;
+ margin: 0;
outline: none;
- padding: 2px 22px 2px 4px;
- width: 158px;
+ padding: 3px 22px 3px 8px;
+ width: 100%;
+ -webkit-box-sizing: border-box;
+ -moz-box-sizing: border-box;
+ box-sizing: border-box;
}
-#admin-menu .dropdown .admin-menu-search-results {
+#admin-menu .admin-menu-search-results .dropdown {
display: block !important;
left: auto !important;
top: 100%;
@@ -197,12 +284,10 @@ body.admin-menu {
width: 186px;
}
-#admin-menu li.highlight {
- background-color: #eee !important;
-}
+#admin-menu li.active-search-item > a,
#admin-menu li.highlight > a {
- border-color: #ccc !important;
- color: #111 !important;
+ background-color: #0074BD !important;
+ color: white !important;
}
/* #210615: Mozilla on Mac fix */
diff --git a/admin_menu.inc b/admin_menu.inc
index e212970..c83889a 100644
--- a/admin_menu.inc
+++ b/admin_menu.inc
@@ -6,6 +6,117 @@
*/
/**
+ * Build the administration menu output.
+ *
+ * @param 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.
+ */
+function admin_menu_output($complete = FALSE) {
+ global $user, $language_interface;
+ $config = config('admin_menu.settings');
+
+ $cache_server_enabled = !$complete;
+ $cid = 'admin_menu:' . $user->uid . ':' . session_id() . ':' . $language_interface->langcode;
+
+ // Try to load and output administration menu from server-side cache. The
+ // cache is only valid if a hash key exists, otherwise it needs to be
+ // regenerated.
+ $old_hash = admin_menu_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 theming 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-menu-site' . drupal_strtolower(preg_replace('/[^a-zA-Z0-9-]/', '-', $GLOBALS['cookie_domain']));
+
+ // @todo Always output container to harden JS-less support.
+ $content['#prefix'] = '<div id="admin-menu" class="' . $classes . '"><div id="admin-menu-wrapper">';
+ $content['#suffix'] = '</div></div>';
+
+ // Load menu builder functions.
+ module_load_include('inc', 'admin_menu');
+
+ // Add administration menu.
+ if (in_array('admin_menu.menu', $components) || $complete) {
+ $content['menu'] = array(
+ '#theme' => 'admin_menu_links',
+ '#wrapper_attributes' => array(
+ 'id' => 'admin-menu-menu',
+ ),
+ '#weight' => 0,
+ );
+
+ $content['menu']['menu'] = admin_menu_links_menu(admin_menu_tree('management'));
+ $content['menu']['menu']['#title'] = t('Admin menu');
+ }
+
+ // Add menu additions.
+ $content['extra']['extra'] = array();
+ if (in_array('admin_menu.icon', $components) || $complete) {
+ $content['icon'] = admin_menu_links_icon();
+ }
+ if (in_array('admin_menu.search', $components) || $complete) {
+ $content['extra']['extra'] += admin_menu_links_search();
+ }
+ if (in_array('admin_menu.account', $components) || $complete) {
+ $content['extra']['extra'] += admin_menu_links_account();
+ }
+ if (in_array('admin_menu.users', $components) || $complete) {
+ $content['extra']['extra'] += admin_menu_links_users();
+ }
+
+ // Allow modules to enhance the menu.
+ // Uses '_output' suffix for consistency with the alter hook (see below).
+ foreach (module_implements('admin_menu_output_build') as $module) {
+ $function = $module . '_admin_menu_output_build';
+ $function($content);
+ }
+
+ if ($content['extra']['extra']) {
+ $content['extra']['#theme'] = 'admin_menu_links';
+ $content['extra']['extra']['#title'] = t('More admin tasks');
+ $content['extra']['#wrapper_attributes'] = array(
+ 'id' => 'admin-menu-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.
+ drupal_alter('admin_menu_output', $content);
+
+ $content = drupal_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_menu_cache_set($cid, md5($content));
+ }
+
+ return $content;
+}
+
+/**
* Build the full administration menu tree from static and expanded dynamic items.
*
* @param $menu_name
@@ -425,7 +536,9 @@ function admin_menu_links_icon() {
$links = array(
'#theme' => 'admin_menu_links',
- '#wrapper_attributes' => array('id' => 'admin-menu-icon'),
+ '#wrapper_attributes' => array(
+ 'id' => 'admin-menu-icon',
+ ),
'#weight' => -100,
);
$links['icon'] = array(
@@ -454,28 +567,6 @@ function admin_menu_links_icon() {
'external' => TRUE,
),
);
- // Add link to drupal.org.
- $links['icon']['drupal.org'] = array(
- '#title' => 'Drupal.org',
- '#weight' => 100,
- '#access' => user_access('display drupal links'),
- '#href' => 'http://drupal.org',
- );
- // Add links to project issue queues.
- foreach (module_list(FALSE, TRUE) as $module) {
- $info = drupal_parse_info_file(drupal_get_path('module', $module) . '/' . $module . '.info');
- if (!isset($info['project']) || isset($links['icon']['drupal.org'][$info['project']])) {
- continue;
- }
- $links['icon']['drupal.org'][$info['project']] = array(
- '#title' => t('@project issue queue', array('@project' => $info['name'])),
- '#weight' => ($info['project'] == 'drupal' ? -10 : 0),
- '#href' => 'http://drupal.org/project/issues/' . $info['project'],
- '#options' => array(
- 'query' => array('version' => (isset($info['core']) ? $info['core'] : 'All')),
- ),
- );
- }
// Add items to flush caches.
$links['icon']['flush-cache'] = array(
'#title' => t('Flush all caches'),
@@ -497,30 +588,6 @@ function admin_menu_links_icon() {
);
}
- // Add link to toggle developer modules (performance).
- $saved_state = variable_get('admin_menu_devel_modules_enabled', NULL);
- $links['icon']['toggle-modules'] = array(
- '#title' => isset($saved_state) ? t('Enable developer modules') : t('Disable developer modules'),
- '#weight' => 88,
- '#access' => user_access('administer modules'),
- '#href' => 'admin_menu/toggle-modules',
- '#options' => array(
- 'query' => $destination + array('token' => drupal_get_token('admin_menu/toggle-modules')),
- ),
- );
-
- // Add Devel module menu links.
- if (module_exists('devel')) {
- $devel_tree = menu_build_tree('devel');
- $devel_links = admin_menu_links_menu($devel_tree);
- if (element_get_visible_children($devel_links)) {
- $links['icon']['devel'] = array(
- '#title' => t('Development'),
- '#weight' => 30,
- ) + $devel_links;
- }
- }
-
return $links;
}
@@ -530,38 +597,18 @@ function admin_menu_links_icon() {
* @see theme_admin_menu_links()
*/
function admin_menu_links_account() {
- $links = array(
- '#theme' => 'admin_menu_links',
- '#wrapper_attributes' => array('id' => 'admin-menu-account'),
- '#weight' => 100,
- );
$links['account'] = array(
- '#title' => format_username($GLOBALS['user']),
- '#weight' => -99,
- '#attributes' => array('class' => array('admin-menu-action', 'admin-menu-account')),
+ '#title' => user_format_name($GLOBALS['user']),
+ '#weight' => 50,
+ '#attributes' => array('class' => array('admin-menu-account')),
'#href' => 'user/' . $GLOBALS['user']->uid,
);
$links['logout'] = array(
'#title' => t('Log out'),
- '#weight' => -100,
- '#attributes' => array('class' => array('admin-menu-action')),
+ '#weight' => 51,
+ '#attributes' => array('class' => array('admin-menu-logout')),
'#href' => 'user/logout',
);
- // Add Devel module switch user links.
- $switch_links = module_invoke('devel', 'switch_user_list');
- if (!empty($switch_links) && count($switch_links) > 1) {
- foreach ($switch_links as $uid => $link) {
- $links['account'][$link['title']] = array(
- '#title' => $link['title'],
- '#description' => $link['attributes']['title'],
- '#href' => $link['href'],
- '#options' => array(
- 'query' => $link['query'],
- 'html' => !empty($link['html']),
- ),
- );
- }
- }
return $links;
}
@@ -571,16 +618,11 @@ function admin_menu_links_account() {
* @see theme_admin_menu_links()
*/
function admin_menu_links_users() {
- $links = array(
- '#theme' => 'admin_menu_links',
- '#wrapper_attributes' => array('id' => 'admin-menu-users'),
- '#weight' => 150,
- );
// Add link to show current authenticated/anonymous users.
$links['user-counter'] = array(
'#title' => admin_menu_get_user_count(),
'#description' => t('Current anonymous / authenticated users'),
- '#weight' => -90,
+ '#weight' => 20,
'#attributes' => array('class' => array('admin-menu-action', 'admin-menu-users')),
'#href' => (user_access('administer users') ? 'admin/people/people' : 'user'),
);
@@ -593,53 +635,45 @@ function admin_menu_links_users() {
* @see theme_admin_menu_links()
*/
function admin_menu_links_search() {
- $links = array(
- '#theme' => 'admin_menu_links',
- '#wrapper_attributes' => array('id' => 'admin-menu-search'),
- '#weight' => 180,
+ $search['search'] = array(
+ '#pre_render' => array(),
+ '#attributes' => array(
+ 'class' => array('admin-menu-search'),
+ ),
);
- $links['search'] = array(
+ $search['search']['search'] = array(
'#type' => 'textfield',
- '#title' => t('Search'),
+ '#title' => t('Admin search'),
'#title_display' => 'attribute',
'#attributes' => array(
'placeholder' => t('Search'),
- 'class' => array('admin-menu-search'),
+ 'autocomplete' => 'off',
+ 'autocorrect' => 'off',
+ 'autocapitalize' => 'off',
),
);
- return $links;
+ return $search;
}
/**
* Form builder function for module settings.
*/
function admin_menu_theme_settings() {
- $form['admin_menu_margin_top'] = array(
+ $config = config('admin_menu.settings');
+ $form['margin_top'] = array(
'#type' => 'checkbox',
'#title' => t('Adjust top margin'),
- '#default_value' => variable_get('admin_menu_margin_top', 1),
- '#description' => t('Shifts the site output down by approximately 20 pixels from the top of the viewport. If disabled, absolute- or fixed-positioned page elements may be covered by the administration menu.'),
+ '#default_value' => $config->get('margin_top'),
+ '#description' => t('Shifts the entire site content down to make room for the administration menu. If disabled, absolute- or fixed-positioned page elements may be covered by the administration menu.'),
);
- $form['admin_menu_position_fixed'] = array(
+ $form['position_fixed'] = array(
'#type' => 'checkbox',
'#title' => t('Keep menu at top of page'),
- '#default_value' => variable_get('admin_menu_position_fixed', 1),
- '#description' => t('Displays the administration menu always at the top of the browser viewport (even when scrolling the page).'),
+ '#default_value' => $config->get('position_fixed'),
+ '#description' => t('Displays the administration menu always at the top of the browser viewport, even when scrolling the page.'),
);
- // @todo Re-confirm this with latest browser versions.
- $form['admin_menu_position_fixed']['#description'] .= '<br /><strong>' . t('In some browsers, this setting may result in a malformed page, an invisible cursor, non-selectable elements in forms, or other issues.') . '</strong>';
- $form['advanced'] = array(
- '#type' => 'vertical_tabs',
- '#title' => t('Advanced settings'),
- );
-
- $form['plugins'] = array(
- '#type' => 'fieldset',
- '#title' => t('Plugins'),
- '#group' => 'advanced',
- );
- $form['plugins']['admin_menu_components'] = array(
+ $form['components'] = array(
'#type' => 'checkboxes',
'#title' => t('Enabled components'),
'#options' => array(
@@ -649,79 +683,22 @@ function admin_menu_theme_settings() {
'admin_menu.users' => t('User counts'),
'admin_menu.account' => t('Account links'),
),
+ '#default_value' => $config->get('components'),
);
- $form['plugins']['admin_menu_components']['#default_value'] = array_keys(array_filter(variable_get('admin_menu_components', $form['plugins']['admin_menu_components']['#options'])));
$process = element_info_property('checkboxes', '#process', array());
- $form['plugins']['admin_menu_components']['#process'] = array_merge(array('admin_menu_settings_process_components'), $process);
+ $form['components']['#process'] = array_merge(array('admin_menu_settings_process_components'), $process);
$form['#attached']['js'][] = drupal_get_path('module', 'admin_menu') . '/admin_menu.admin.js';
- $form['tweaks'] = array(
- '#type' => 'fieldset',
- '#title' => t('System tweaks'),
- '#group' => 'advanced',
- );
- $form['tweaks']['admin_menu_tweak_modules'] = array(
- '#type' => 'checkbox',
- '#title' => t('Collapse module groups on the <a href="!modules-url">%modules</a> page', array(
- '%modules' => t('Modules'),
- '!modules-url' => url('admin/modules'),
- )),
- '#default_value' => variable_get('admin_menu_tweak_modules', 0),
+ $form['actions'] = array(
+ '#type' => 'actions',
);
- if (module_exists('util')) {
- $form['tweaks']['admin_menu_tweak_modules']['#description'] .= '<br /><strong>' . t('If the Utility module was installed for this purpose, it can be safely disabled and uninstalled.') . '</strong>';
- }
- $form['tweaks']['admin_menu_tweak_permissions'] = array(
- '#type' => 'checkbox',
- '#title' => t('Collapse module groups on the <a href="@permissions-url">%permissions</a> page', array(
- '%permissions' => t('Permissions'),
- '@permissions-url' => url('admin/people/permissions'),
- )),
- '#default_value' => variable_get('admin_menu_tweak_permissions', 0),
- );
- $form['tweaks']['admin_menu_tweak_tabs'] = array(
- '#type' => 'checkbox',
- '#title' => t('Move local tasks into menu'),
- '#default_value' => variable_get('admin_menu_tweak_tabs', 0),
- '#description' => t('Moves the tabs on all pages into the administration menu. Only possible for themes using the CSS classes <code>tabs primary</code> and <code>tabs secondary</code>.'),
+ $form['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Save configuration'),
);
- $form['performance'] = array(
- '#type' => 'fieldset',
- '#title' => t('Performance'),
- '#group' => 'advanced',
- );
- $form['performance']['admin_menu_cache_client'] = array(
- '#type' => 'checkbox',
- '#title' => t('Cache menu in client-side browser'),
- '#default_value' => variable_get('admin_menu_cache_client', 1),
- );
- // Fetch all available modules manually, since module_list() only returns
- // currently enabled modules, which makes this setting pointless if developer
- // modules are currently disabled.
- $all_modules = array();
- $result = db_query("SELECT name, filename, info FROM {system} WHERE type = 'module' ORDER BY name ASC");
- foreach ($result as $module) {
- if (file_exists($module->filename)) {
- $info = unserialize($module->info);
- $all_modules[$module->name] = $info['name'];
- }
- }
- $devel_modules = variable_get('admin_menu_devel_modules', _admin_menu_developer_modules());
- $devel_modules = array_intersect_key($all_modules, array_flip($devel_modules));
- $form['performance']['admin_menu_devel_modules_skip'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Developer modules to keep enabled'),
- '#default_value' => variable_get('admin_menu_devel_modules_skip', array()),
- '#options' => $devel_modules,
- '#access' => !empty($devel_modules),
- '#description' => t('The selected modules will not be disabled when the link %disable-developer-modules below the icon in the menu is invoked.', array(
- '%disable-developer-modules' => t('Disable developer modules'),
- )),
- );
-
- return system_settings_form($form);
+ return $form;
}
/**
@@ -741,134 +718,14 @@ function admin_menu_settings_process_components($element) {
}
/**
- * Form validation handler for admin_menu_theme_settings().
+ * Submit handler for admin_menu_theme_settings().
*/
-function admin_menu_theme_settings_validate(&$form, &$form_state) {
- // Change the configured components to Boolean values.
- foreach ($form_state['values']['admin_menu_components'] as $component => &$enabled) {
- $enabled = (bool) $enabled;
- }
-}
-
-/**
- * Implementation of hook_form_FORM_ID_alter().
- *
- * Extends Devel module with Administration menu developer settings.
- */
-function _admin_menu_form_devel_admin_settings_alter(&$form, $form_state) {
- // Shift system_settings_form buttons.
- $weight = isset($form['buttons']['#weight']) ? $form['buttons']['#weight'] : 0;
- $form['buttons']['#weight'] = $weight + 1;
-
- $form['admin_menu'] = array(
- '#type' => 'fieldset',
- '#title' => t('Administration menu settings'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- );
- $display_options = array('mid', 'weight', 'pid');
- $display_options = array(0 => t('None'), 'mlid' => t('Menu link ID'), 'weight' => t('Weight'), 'plid' => t('Parent link ID'));
- $form['admin_menu']['admin_menu_display'] = array(
- '#type' => 'radios',
- '#title' => t('Display additional data for each menu item'),
- '#default_value' => variable_get('admin_menu_display', 0),
- '#options' => $display_options,
- '#description' => t('Display the selected items next to each menu item link.'),
- );
- $form['admin_menu']['admin_menu_show_all'] = array(
- '#type' => 'checkbox',
- '#title' => t('Display all menu items'),
- '#default_value' => variable_get('admin_menu_show_all', 0),
- '#description' => t('If enabled, all menu items are displayed regardless of your site permissions. <em>Note: Do not enable on a production site.</em>'),
- );
-}
-
-/**
- * Menu callback; Enable/disable developer modules.
- *
- * This can save up to 150ms on each uncached page request.
- */
-function admin_menu_toggle_modules() {
- if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], current_path())) {
- return MENU_ACCESS_DENIED;
- }
-
- $rebuild = FALSE;
- $saved_state = variable_get('admin_menu_devel_modules_enabled', NULL);
- if (isset($saved_state)) {
- // Re-enable modules that were enabled before.
- module_enable($saved_state);
- variable_del('admin_menu_devel_modules_enabled');
- drupal_set_message(t('Enabled these modules: !module-list.', array('!module-list' => implode(', ', $saved_state))));
- $rebuild = TRUE;
- }
- else {
- // Allow site admins to override this variable via settings.php.
- $devel_modules = variable_get('admin_menu_devel_modules', _admin_menu_developer_modules());
- // Store currently enabled modules in a variable.
- $devel_modules = array_intersect(module_list(FALSE, FALSE), $devel_modules);
- $devel_modules = array_diff($devel_modules, variable_get('admin_menu_devel_modules_skip', array()));
- if (!empty($devel_modules)) {
- variable_set('admin_menu_devel_modules_enabled', $devel_modules);
- // Disable developer modules.
- module_disable($devel_modules);
- drupal_set_message(t('Disabled these modules: !module-list.', array('!module-list' => implode(', ', $devel_modules))));
- $rebuild = TRUE;
- }
- else {
- drupal_set_message(t('No developer modules are enabled.'));
- }
- }
- if ($rebuild) {
- // Make sure everything is rebuilt, basically a combination of the calls
- // from system_modules() and system_modules_submit().
- drupal_theme_rebuild();
- menu_rebuild();
- cache_clear_all('schema', 'cache');
- cache_clear_all();
- drupal_clear_css_cache();
- drupal_clear_js_cache();
- // Synchronize to catch any actions that were added or removed.
- actions_synchronize();
- // Finally, flush admin_menu's cache.
- admin_menu_flush_caches();
- }
- drupal_goto();
-}
-
-/**
- * Helper function to return a default list of developer modules.
- */
-function _admin_menu_developer_modules() {
- return array(
- 'admin_devel',
- 'cache_disable',
- 'coder',
- 'content_copy',
- 'context_ui',
- 'debug',
- 'delete_all',
- 'demo',
- 'devel',
- 'devel_node_access',
- 'devel_themer',
- 'field_ui',
- 'fontyourface_ui',
- 'form_controller',
- 'imagecache_ui',
- 'journal',
- 'l10n_client',
- 'l10n_update',
- 'macro',
- 'rules_admin',
- 'stringoverrides',
- 'trace',
- 'upgrade_status',
- 'user_display_ui',
- 'util',
- 'views_ui',
- 'views_theme_wizard',
- );
+function admin_menu_theme_settings_submit($form, $form_state) {
+ $config = config('admin_menu.settings');
+ $config->set('margin_top', $form_state['values']['margin_top']);
+ $config->set('position_fixed', $form_state['values']['position_fixed']);
+ $config->set('components', array_values(array_filter($form_state['values']['components'])));
+ $config->save();
}
/**
@@ -958,7 +815,7 @@ function update_admin_menu_cache_info() {
function _admin_menu_flush_cache($name = NULL) {
switch ($name) {
case 'admin_menu':
- admin_menu_flush_caches();
+ cache('admin_menu')->flush();
break;
case 'menu':
@@ -1031,3 +888,113 @@ function theme_admin_menu_icon($variables) {
return '<img class="admin-menu-icon" src="' . $variables['src'] . '" width="16" height="16" alt="' . $variables['alt'] . '" />';
}
+
+/**
+ * Render a themed list of links.
+ *
+ * @param $variables
+ * - elements: A renderable array of links using the following keys:
+ * - #attributes: Optional array of attributes for the list item, processed
+ * via drupal_attributes().
+ * - #title: Title of the link, passed to l().
+ * - #href: Optional path of the link, passed to l(). When omitted, the
+ * element's '#title' is rendered without link.
+ * - #description: Optional alternative text for the link, passed to l().
+ * - #options: Optional alternative text for the link, passed to l().
+ * The array key of each child element itself is passed as path for l().
+ */
+function theme_admin_menu_links($variables) {
+ $destination = &drupal_static('admin_menu_destination');
+ $elements = $variables['elements'];
+
+ if (!isset($destination)) {
+ $destination = drupal_get_destination();
+ $destination = $destination['destination'];
+ }
+
+ // The majority of items in the menu are sorted already, but since modules
+ // may add or change arbitrary items anywhere, there is no way around sorting
+ // everything again. element_sort() is not sufficient here, as it
+ // intentionally retains the order of elements having the same #weight,
+ // whereas menu links are supposed to be ordered by #weight and #title.
+ uasort($elements, 'admin_menu_element_sort');
+ $elements['#sorted'] = TRUE;
+
+ $output = '';
+ foreach (element_children($elements) as $path) {
+ // Early-return nothing if user does not have access.
+ if (isset($elements[$path]['#access']) && !$elements[$path]['#access']) {
+ continue;
+ }
+ $elements[$path] += array(
+ '#attributes' => array(),
+ '#options' => array(),
+ );
+ // Render children to determine whether this link is expandable.
+ if (isset($elements[$path]['#type']) || isset($elements[$path]['#theme']) || isset($elements[$path]['#pre_render'])) {
+ $elements[$path]['#children'] = drupal_render($elements[$path]);
+ }
+ else {
+ $elements[$path]['#children'] = theme('admin_menu_links', array('elements' => $elements[$path]));
+ if (!empty($elements[$path]['#children'])) {
+ $elements[$path]['#attributes']['class'][] = 'expandable';
+ }
+ if (isset($elements[$path]['#attributes']['class'])) {
+ $elements[$path]['#attributes']['class'] = $elements[$path]['#attributes']['class'];
+ }
+ }
+
+ $link = '';
+ // Handle menu links.
+ if (isset($elements[$path]['#href'])) {
+ // Strip destination query string from href attribute and apply a CSS class
+ // for our JavaScript behavior instead.
+ if (isset($elements[$path]['#options']['query']['destination']) && $elements[$path]['#options']['query']['destination'] == $destination) {
+ unset($elements[$path]['#options']['query']['destination']);
+ $elements[$path]['#options']['attributes']['class'][] = 'admin-menu-destination';
+ }
+
+ $link = l($elements[$path]['#title'], $elements[$path]['#href'], $elements[$path]['#options']);
+ }
+ // Handle plain text items, but do not interfere with menu additions.
+ elseif (!isset($elements[$path]['#type']) && isset($elements[$path]['#title'])) {
+ if (!empty($elements[$path]['#options']['html'])) {
+ $title = $elements[$path]['#title'];
+ }
+ else {
+ $title = check_plain($elements[$path]['#title']);
+ }
+ $attributes = '';
+ if (isset($elements[$path]['#options']['attributes'])) {
+ $attributes = drupal_attributes($elements[$path]['#options']['attributes']);
+ }
+ $link = '<span' . $attributes . '>' . $title . '</span>';
+ }
+
+ $output .= '<li' . drupal_attributes($elements[$path]['#attributes']) . '>';
+ $output .= $link . $elements[$path]['#children'];
+ $output .= '</li>';
+ }
+ if ($output) {
+ $elements['#wrapper_attributes']['class'][] = 'dropdown';
+ $attributes = drupal_attributes($elements['#wrapper_attributes']);
+ $output = '<ul' . $attributes . '>' . $output . '</ul>';
+ }
+ return $output;
+}
+
+/**
+ * Function used by uasort to sort structured arrays by #weight AND #title.
+ */
+function admin_menu_element_sort($a, $b) {
+ // @see element_sort()
+ $a_weight = isset($a['#weight']) ? $a['#weight'] : 0;
+ $b_weight = isset($b['#weight']) ? $b['#weight'] : 0;
+ if ($a_weight == $b_weight) {
+ // @see element_sort_by_title()
+ $a_title = isset($a['#title']) ? $a['#title'] : '';
+ $b_title = isset($b['#title']) ? $b['#title'] : '';
+ return strnatcasecmp($a_title, $b_title);
+ }
+ return ($a_weight < $b_weight) ? -1 : 1;
+}
diff --git a/admin_menu.info b/admin_menu.info
index 0543960..3fe9ae7 100644
--- a/admin_menu.info
+++ b/admin_menu.info
@@ -1,9 +1,6 @@
name = Administration menu
-description = "Provides a dropdown menu to most administrative tasks and other common destinations (to users with the proper permissions)."
-package = Administration
-core = 7.x
-configure = admin/config/administration/admin_menu
-; Requires menu_build_tree() conditions; available after 7.10.
-; @see http://drupal.org/node/1025582
-dependencies[] = system (>7.10)
-files[] = tests/admin_menu.test
+description = "Provides a dropdown menu to most administrative tasks and other common destinations."
+package = Core
+core = 8.x
+configure = admin/config/administration/admin-menu
+version = VERSION
diff --git a/admin_menu.install b/admin_menu.install
index 70e31c6..412b0c1 100644
--- a/admin_menu.install
+++ b/admin_menu.install
@@ -26,97 +26,3 @@ function admin_menu_install() {
->condition('name', 'admin_menu')
->execute();
}
-
-/**
- * Implements hook_uninstall().
- */
-function admin_menu_uninstall() {
- // Delete variables.
- variable_del('admin_menu_components');
- variable_del('admin_menu_devel_modules');
- variable_del('admin_menu_devel_modules_enabled');
- variable_del('admin_menu_devel_modules_skip');
- variable_del('admin_menu_margin_top');
- variable_del('admin_menu_position_fixed');
- variable_del('admin_menu_tweak_modules');
- variable_del('admin_menu_tweak_tabs');
- variable_del('admin_menu_show_all');
- variable_del('admin_menu_display');
- variable_del('admin_menu_cache_server');
- variable_del('admin_menu_cache_client');
-}
-
-/**
- * Ensure that admin_menu is rebuilt after upgrading to D6.
- */
-function admin_menu_update_6000() {
- // Drop the {admin_menu} table in admin_menu_update_6000() on sites that used
- // one of the later patches in #132524.
- if (db_table_exists('admin_menu')) {
- db_drop_table('admin_menu');
- }
-}
-
-/**
- * Wipe and rebuild so we can switch the icon path to <front>.
- */
-function admin_menu_update_6001() {
- db_delete('menu_links')->condition('module', 'admin_menu')->execute();
- menu_cache_clear('admin_menu');
-}
-
-/**
- * Add {cache_admin_menu} table.
- */
-function admin_menu_update_7300() {
- if (!db_table_exists('cache_admin_menu')) {
- $schema = drupal_get_schema_unprocessed('system', 'cache');
- db_create_table('cache_admin_menu', $schema);
- }
-}
-
-/**
- * Increase the module weight.
- *
- * @see admin_menu_install()
- */
-function admin_menu_update_7302() {
- db_update('system')
- ->fields(array('weight' => 100))
- ->condition('type', 'module')
- ->condition('name', 'admin_menu')
- ->execute();
-}
-
-/**
- * Remove local tasks from {menu_links} table.
- */
-function admin_menu_update_7303() {
- db_delete('menu_router')
- ->condition('path', 'admin/%', 'LIKE')
- ->condition('type', MENU_IS_LOCAL_TASK, '&')
- ->execute();
-}
-
-/**
- * Remove obsolete 'admin_menu' menu and all orphan links in it.
- */
-function admin_menu_update_7304() {
- // Remove the custom menu used by 6.x-1.x.
- if (db_table_exists('menu_custom')) {
- db_delete('menu_custom')->condition('menu_name', 'admin_menu')->execute();
- }
-
- // 6.x-1.x cloned the entire link structure below the path 'admin' into a
- // separate 'menu_name' "admin_menu" with 'module' "admin_menu". 6.x-3.x and
- // early alpha versions of 7.x-3.x still did something similar. All of these
- // records are obsolete. Removal of the 'module' records (without different
- // menu_name) is particularly important, since they would otherwise appear
- // as duplicate links.
- db_delete('menu_links')
- ->condition(db_or()
- ->condition('module', 'admin_menu')
- ->condition('menu_name', 'admin_menu')
- )
- ->execute();
-}
diff --git a/admin_menu.js b/admin_menu.js
index 2e28b55..7a6039c 100644
--- a/admin_menu.js
+++ b/admin_menu.js
@@ -17,9 +17,6 @@ Drupal.behaviors.adminMenu = {
suppress: false,
margin_top: false,
position_fixed: false,
- tweak_modules: false,
- tweak_permissions: false,
- tweak_tabs: false,
destination: '',
basePath: settings.basePath,
hash: 0,
@@ -34,14 +31,14 @@ Drupal.behaviors.adminMenu = {
// fetched from the server and cached in the browser.
if (!$adminMenu.length && settings.admin_menu.hash) {
Drupal.admin.getCache(settings.admin_menu.hash, function (response) {
- if (typeof response == 'string' && response.length > 0) {
- $('body', context).append(response);
- }
- var $adminMenu = $('#admin-menu:not(.admin-menu-processed)', context);
- // Apply our behaviors.
- Drupal.admin.attachBehaviors(context, settings, $adminMenu);
- // Allow resize event handlers to recalculate sizes/positions.
- $(window).triggerHandler('resize');
+ if (typeof response == 'string' && response.length > 0) {
+ $('body', context).append(response);
+ }
+ var $adminMenu = $('#admin-menu:not(.admin-menu-processed)', context);
+ // Apply our behaviors.
+ Drupal.admin.attachBehaviors(context, settings, $adminMenu);
+ // Allow resize event handlers to recalculate sizes/positions.
+ $(window).triggerHandler('resize');
});
}
// If the menu is in the output already, this means there is a new version.
@@ -53,44 +50,11 @@ Drupal.behaviors.adminMenu = {
};
/**
- * Collapse fieldsets on Modules page.
+ * Apply active trail highlighting based on current path.
*/
-Drupal.behaviors.adminMenuCollapseModules = {
- attach: function (context, settings) {
- if (settings.admin_menu.tweak_modules) {
- $('#system-modules fieldset:not(.collapsed)', context).addClass('collapsed');
- }
- }
-};
-
-/**
- * Collapse modules on Permissions page.
- */
-Drupal.behaviors.adminMenuCollapsePermissions = {
- attach: function (context, settings) {
- if (settings.admin_menu.tweak_permissions) {
- // Freeze width of first column to prevent jumping.
- $('#permissions th:first', context).css({ width: $('#permissions th:first', context).width() });
- // Attach click handler.
- $modules = $('#permissions tr:has(td.module)', context).once('admin-menu-tweak-permissions', function () {
- var $module = $(this);
- $module.bind('click.admin-menu', function () {
- // @todo Replace with .nextUntil() in jQuery 1.4.
- $module.nextAll().each(function () {
- var $row = $(this);
- if ($row.is(':has(td.module)')) {
- return false;
- }
- $row.toggleClass('element-hidden');
- });
- });
- });
- // Collapse all but the targeted permission rows set.
- if (window.location.hash.length) {
- $modules = $modules.not(':has(' + window.location.hash + ')');
- }
- $modules.trigger('click.admin-menu');
- }
+Drupal.admin.behaviors.toolbarActiveTrail = function (context, settings, $adminMenu) {
+ if (settings.admin_menu.activeTrail) {
+ $adminMenu.find('#admin-menu-menu > li > ul > li > a[href="' + settings.admin_menu.activeTrail + '"]').addClass('active-trail');
}
};
@@ -121,6 +85,7 @@ Drupal.admin.getCache = function (hash, onSuccess) {
if (Drupal.admin.hashes.hash !== undefined) {
return Drupal.admin.hashes.hash;
}
+
$.ajax({
cache: true,
type: 'GET',
@@ -178,21 +143,6 @@ Drupal.admin.behaviors.positionFixed = function (context, settings, $adminMenu)
};
/**
- * Move page tabs into administration menu.
- */
-Drupal.admin.behaviors.pageTabs = function (context, settings, $adminMenu) {
- if (settings.admin_menu.tweak_tabs) {
- var $tabs = $(context).find('ul.tabs.primary');
- $adminMenu.find('#admin-menu-wrapper > ul').eq(1)
- .append($tabs.find('li').addClass('admin-menu-tab'));
- $(context).find('ul.tabs.secondary')
- .appendTo('#admin-menu-wrapper > ul > li.admin-menu-tab.active')
- .removeClass('secondary');
- $tabs.remove();
- }
-};
-
-/**
* Perform dynamic replacements in cached menu.
*/
Drupal.admin.behaviors.replacements = function (context, settings, $adminMenu) {
@@ -213,39 +163,120 @@ Drupal.admin.behaviors.destination = function (context, settings, $adminMenu) {
};
/**
+ * Adjust the toolbar top level items based on the available viewport width.
+ */
+Drupal.admin.behaviors.collapseWidth = function (context, settings, $adminMenu) {
+ var $menu = $adminMenu.find('#admin-menu-menu');
+ var $extra = $adminMenu.find('#admin-menu-extra');
+ var resizeTimeout;
+
+ $(window).on('resize.adminMenu', function(event) {
+ clearTimeout(resizeTimeout);
+ resizeTimeout = setTimeout(function() {
+ // Expand the menu items to their full width to check their size.
+ $menu.removeClass('dropdown').addClass('top-level');
+ $extra.removeClass('dropdown').addClass('top-level');
+
+ $adminMenu.trigger('beforeResize');
+
+ var menuWidth = $menu.width();
+ var extraWidth = $extra.width();
+ var availableWidth = $adminMenu.width() - $adminMenu.find('#admin-menu-icon').width();
+
+ // Collapse the extra items first if needed.
+ if (availableWidth - menuWidth - extraWidth < 20) {
+ $extra.addClass('dropdown').removeClass('top-level');
+ extraWidth = $extra.width();
+ }
+ // See if the menu also needs to be collapsed.
+ if (availableWidth - menuWidth - extraWidth < 20) {
+ $menu.addClass('dropdown').removeClass('top-level');
+ }
+ $adminMenu.trigger('afterResize');
+ }, 50);
+ }).triggerHandler('resize.adminMenu');
+}
+
+/**
* Apply JavaScript-based hovering behaviors.
*
* @todo This has to run last. If another script registers additional behaviors
* it will not run last.
*/
Drupal.admin.behaviors.hover = function (context, settings, $adminMenu) {
- // Delayed mouseout.
- $('li.expandable', $adminMenu).hover(
- function () {
- // Stop the timer.
- clearTimeout(this.sfTimer);
- // Display child lists.
- $('> ul', this)
- .css({left: 'auto', display: 'block'})
- // Immediately hide nephew lists.
- .parent().siblings('li').children('ul').css({left: '-999em', display: 'none'});
- },
- function () {
- // Start the timer.
- var uls = $('> ul', this);
- this.sfTimer = setTimeout(function () {
- uls.css({left: '-999em', display: 'none'});
- }, 400);
+ // Bind events for opening and closing menus on hover/click/touch.
+ $adminMenu.on('mouseenter', 'li.expandable', expandChild);
+ $adminMenu.on('mouseleave', 'li.expandable', closeChild);
+
+ // On touch devices, the first click on an expandable link should not go to
+ // that page, but a second click will. Use touch start/end events to target
+ // these devices.
+ var touchElement;
+ var needsExpanding;
+ $adminMenu.on('touchstart touchend click', 'li.expandable > a, li.expandable > span', function(e) {
+ // The touchstart event fires before all other events, including mouseenter,
+ // allowing us to check the expanded state consistently across devices.
+ if (e.type === 'touchstart') {
+ touchElement = e.target
+ needsExpanding = $(this).siblings('ul').length > 0 && !$(this).siblings('ul').hasClass('expanded');
}
- );
+ // If clicking on a not-yet-expanded item, expand it and suppress the click.
+ if ((e.type === 'click' || e.type === 'touchend') && touchElement) {
+ if (touchElement === e.target) {
+ if (needsExpanding) {
+ expandChild.apply($(this).parent()[0], [e]);
+ e.preventDefault();
+ }
+ else if ($(this).is('span')) {
+ closeChild.apply($(this).parent()[0], [e]);
+ }
+ }
+ // If the touch ended on a different element than it started, suppress it.
+ else if (touchElement !== e.target) {
+ e.preventDefault();
+ }
+ }
+ });
+
+ // Close all menus if clicking outside the menu.
+ $(document).bind('click', function (e) {
+ if ($(e.target).closest($adminMenu).length === 0) {
+ $adminMenu.find('ul').removeClass('expanded');
+ }
+ });
+
+ function expandChild(e) {
+ // Stop the timer.
+ clearTimeout(this.sfTimer);
+
+ // Display child lists.
+ var $childList = $(this).children('ul');
+
+ // Add classes for the expanded trail of links.
+ $childList
+ .parents('ul').addBack().addClass('expanded')
+ .siblings('a, span').addClass('expanded-trail');
+ // Immediately hide nephew lists.
+ $childList.parent().siblings('li')
+ .find('ul.expanded').removeClass('expanded').end()
+ .find('.expanded-trail').removeClass('expanded-trail');
+ }
+ function closeChild(e) {
+ // Start the timer.
+ var $uls = $(this).find('> ul');
+ var $link = $(this).find('> a, > span');
+ this.sfTimer = setTimeout(function () {
+ $uls.removeClass('expanded');
+ $link.removeClass('expanded-trail');
+ }, 400);
+ }
};
/**
* Apply the search bar functionality.
*/
Drupal.admin.behaviors.search = function (context, settings, $adminMenu) {
- // @todo Add a HTML ID.
- var $input = $('input.admin-menu-search', $adminMenu);
+ var $input = $adminMenu.find('.admin-menu-search input');
// Initialize the current search needle.
var needle = $input.val();
// Cache of all links that can be matched in the menu.
@@ -253,21 +284,25 @@ Drupal.admin.behaviors.search = function (context, settings, $adminMenu) {
// Minimum search needle length.
var needleMinLength = 2;
// Append the results container.
- var $results = $('<div />').insertAfter($input);
+ var $results = $('<div class="admin-menu-search-results" />').insertAfter($input.parent());
/**
* Executes the search upon user input.
*/
- function keyupHandler() {
- var matches, $html, value = $(this).val();
+ function keyupHandler(e) {
+ var matches, $html, $hideItems, value = $(this).val();
+
// Only proceed if the search needle has changed.
- if (value !== needle) {
+ if (value !== needle || e.type === 'focus') {
needle = value;
// Initialize the cache of menu links upon first search.
if (!links && needle.length >= needleMinLength) {
- // @todo Limit to links in dropdown menus; i.e., skip menu additions.
- links = buildSearchIndex($adminMenu.find('li:not(.admin-menu-action, .admin-menu-action li) > a'));
+ links = buildSearchIndex($adminMenu.find('#admin-menu-menu .dropdown li:not(.admin-menu-action, .admin-menu-action li) > a'));
}
+
+ // Close any open items.
+ $adminMenu.find('li.highlight').trigger('mouseleave').removeClass('highlight');
+
// Empty results container when deleting search text.
if (needle.length < needleMinLength) {
$results.empty();
@@ -280,6 +315,7 @@ Drupal.admin.behaviors.search = function (context, settings, $adminMenu) {
// Display results.
$results.empty().append($html);
}
+ $adminMenu.trigger('searchChanged');
}
}
@@ -317,13 +353,13 @@ Drupal.admin.behaviors.search = function (context, settings, $adminMenu) {
* Builds the search result list in a detached DOM node.
*/
function buildResultsList(matches) {
- var $html = $('<ul class="dropdown admin-menu-search-results" />');
+ var $html = $('<ul class="dropdown" />');
$.each(matches, function () {
var result = this.text;
var $element = $(this.element);
// Check whether there is a top-level category that can be prepended.
- var $category = $element.closest('#admin-menu-wrapper > ul > li');
+ var $category = $element.closest('#admin-menu-menu > li > ul > li');
var categoryText = $category.find('> a').text()
if ($category.length && categoryText) {
result = categoryText + ': ' + result;
@@ -341,7 +377,18 @@ Drupal.admin.behaviors.search = function (context, settings, $adminMenu) {
*/
function resultsHandler(e) {
var $this = $(this);
- var show = e.type === 'mouseenter' || e.type === 'focusin';
+ var show = e.type === 'mouseenter' || e.type === 'focusin' || e.type === 'touchstart';
+ // Supress the normal click handling on first touch, only highlighting.
+ if (e.type === 'touchstart' && !$(this).hasClass('active-search-item')) {
+ e.preventDefault();
+ }
+ if (show) {
+ $adminMenu.find('.active-search-item').removeClass('active-search-item');
+ $(this).addClass('active-search-item');
+ }
+ else {
+ $(this).removeClass('active-search-item');
+ }
$this.trigger(show ? 'showPath' : 'hidePath', [this]);
}
@@ -359,23 +406,46 @@ Drupal.admin.behaviors.search = function (context, settings, $adminMenu) {
*/
function highlightPathHandler(e, link) {
if (link) {
+ $adminMenu.find('li.highlight').removeClass('highlight');
var $original = $(link).data('original-link');
var show = e.type === 'showPath';
// Toggle an additional CSS class to visually highlight the matching link.
- // @todo Consider using same visual appearance as regular hover.
$original.toggleClass('highlight', show);
$original.trigger(show ? 'mouseenter' : 'mouseleave');
}
}
+ function resetSearchDisplay(e) {
+ $hideItems = $adminMenu.find('#admin-menu-extra > li > ul > li:not(li.admin-menu-search)').css('display', '');
+ }
+ function updateSearchDisplay(e) {
+ // Build the list of extra items to be hidden if in small window mode.
+ $hideItems = $adminMenu.find('#admin-menu-extra > li > ul > li:not(li.admin-menu-search)').css('display', '');
+ if ($results.children().length) {
+ if ($adminMenu.find('#admin-menu-extra').hasClass('dropdown')) {
+ $hideItems.css('display', 'none');
+ }
+ }
+ }
+
// Attach showPath/hidePath handler to search result entries.
- $results.delegate('li', 'mouseenter mouseleave focus blur', resultsHandler);
- // Hide the result list after a link has been clicked, useful for overlay.
- $results.delegate('li', 'click', resultsClickHandler);
+ $results.on('touchstart mouseenter focus blur', 'li', resultsHandler);
+ // Hide the result list after a link has been clicked.
+ $results.on('click', 'li', resultsClickHandler);
// Attach hover/active highlight behavior to search result entries.
- $adminMenu.delegate('.admin-menu-search-results li', 'showPath hidePath', highlightPathHandler);
+ $adminMenu.on('showPath hidePath', '.admin-menu-search-results li', highlightPathHandler);
+ // Show/hide the extra parts of the menu on resize.
+ $adminMenu.on('beforeResize', resetSearchDisplay)
+ $adminMenu.on('afterResize searchChanged', updateSearchDisplay);
// Attach the search input event handler.
- $input.bind('keyup search', keyupHandler);
+ $input.bind('focus keyup search', keyupHandler);
+
+ // Close search if clicking outside the menu.
+ $(document).on('click', function (e) {
+ if ($(e.target).closest($adminMenu).length === 0) {
+ $results.empty();
+ }
+ });
};
/**
diff --git a/admin_menu.module b/admin_menu.module
index 8a8dee1..25fd257 100644
--- a/admin_menu.module
+++ b/admin_menu.module
@@ -6,63 +6,10 @@
*/
/**
- * Implements hook_help().
- */
-function admin_menu_help($path, $arg) {
- switch ($path) {
- case 'admin/config/administration/admin_menu':
- return '<p>' . t('The administration menu module provides a dropdown menu arranged for one- or two-click access to most administrative tasks and other common destinations (to users with the proper permissions). Use the settings below to customize the appearance of the menu.') . '</p>';
-
- case 'admin/help#admin_menu':
- $output = '';
- $output .= '<p>' . t('The administration menu module provides a dropdown menu arranged for one- or two-click access to most administrative tasks and other common destinations (to users with the proper permissions). Administration menu also displays the number of anonymous and authenticated users, and allows modules to add their own custom menu items. Integration with the menu varies from module to module; the contributed module <a href="@drupal">Devel</a>, for instance, makes strong use of the administration menu module to provide quick access to development tools.', array('@drupal' => 'http://drupal.org/project/devel')) . '</p>';
- $output .= '<p>' . t('The administration menu <a href="@settings">settings page</a> allows you to modify some elements of the menu\'s behavior and appearance. Since the appearance of the menu is dependent on your site theme, substantial customizations require modifications to your site\'s theme and CSS files. See the advanced module README.txt file for more information on theme and CSS customizations.', array('@settings' => url('admin/config/administration/admin_menu'))) . '</p>';
- $output .= '<p>' . t('The menu items displayed in the administration menu depend upon the actual permissions of the viewer. First, the administration menu is only displayed to users in roles with the <em>Access administration menu</em> (admin_menu module) permission. Second, a user must be a member of a role with the <em>Access administration pages</em> (system module) permission to view administrative links. And, third, only currently permitted links are displayed; for example, if a user is not a member of a role with the permissions <em>Administer permissions</em> (user module) and <em>Administer users</em> (user module), the <em>User management</em> menu item is not displayed.') . '</p>';
- return $output;
- }
-}
-
-/**
- * Implements hook_permission().
- */
-function admin_menu_permission() {
- return array(
- 'access administration menu' => array(
- 'title' => t('Access administration menu'),
- 'description' => t('Display the administration menu at the top of each page.'),
- ),
- 'flush caches' => array(
- 'title' => t('Flush caches'),
- 'description' => t('Access links to flush caches in the administration menu.'),
- ),
- 'display drupal links' => array(
- 'title' => t('Display Drupal links'),
- 'description' => t('Provide Drupal.org links in the administration menu.'),
- ),
- );
-}
-
-/**
- * Implements hook_theme().
- */
-function admin_menu_theme() {
- return array(
- 'admin_menu_links' => array(
- 'render element' => 'elements',
- ),
- 'admin_menu_icon' => array(
- 'variables' => array('src' => NULL, 'alt' => NULL),
- 'file' => 'admin_menu.inc',
- ),
- );
-}
-
-/**
* Implements hook_menu().
*/
function admin_menu_menu() {
// AJAX callback.
- // @see http://drupal.org/project/js
$items['js/admin_menu/cache'] = array(
'page callback' => 'admin_menu_js_cache',
'delivery callback' => 'admin_menu_deliver',
@@ -87,12 +34,6 @@ function admin_menu_menu() {
'file' => 'admin_menu.inc',
);
// Menu link callbacks.
- $items['admin_menu/toggle-modules'] = array(
- 'page callback' => 'admin_menu_toggle_modules',
- 'access arguments' => array('administer modules'),
- 'type' => MENU_CALLBACK,
- 'file' => 'admin_menu.inc',
- );
$items['admin_menu/flush-cache'] = array(
'page callback' => 'admin_menu_flush_cache',
'access arguments' => array('flush caches'),
@@ -103,11 +44,43 @@ function admin_menu_menu() {
}
/**
+ * Implements hook_permission().
+ */
+function admin_menu_permission() {
+ return array(
+ 'access administration menu' => array(
+ 'title' => t('Access administration menu'),
+ 'description' => t('Display the administration menu at the top of each page.'),
+ ),
+ 'flush caches' => array(
+ 'title' => t('Flush caches'),
+ 'description' => t('Access links to flush caches in the administration menu.'),
+ ),
+ );
+}
+
+/**
+ * Implements hook_theme().
+ */
+function admin_menu_theme() {
+ return array(
+ 'admin_menu_links' => array(
+ 'render element' => 'elements',
+ 'file' => 'admin_menu.inc',
+ ),
+ 'admin_menu_icon' => array(
+ 'variables' => array('src' => NULL, 'alt' => NULL),
+ 'file' => 'admin_menu.inc',
+ ),
+ );
+}
+
+/**
* Implements hook_menu_alter().
*/
function admin_menu_menu_alter(&$items) {
// Flush client-side caches whenever the menu is rebuilt.
- admin_menu_flush_caches();
+ cache('admin_menu')->flush();
}
/**
@@ -115,7 +88,7 @@ function admin_menu_menu_alter(&$items) {
*/
function admin_menu_menu_link_insert($link) {
// Flush all of our caches to pick up the link.
- admin_menu_flush_caches();
+ cache('admin_menu')->flush();
}
/**
@@ -123,7 +96,7 @@ function admin_menu_menu_link_insert($link) {
*/
function admin_menu_menu_link_update($link) {
// Flush all of our caches to pick up the link.
- admin_menu_flush_caches();
+ cache('admin_menu')->flush();
}
/**
@@ -131,22 +104,7 @@ function admin_menu_menu_link_update($link) {
*/
function admin_menu_menu_link_delete($link) {
// Flush all of our caches to pick up the link.
- admin_menu_flush_caches();
-}
-
-/**
- * Implements hook_system_info_alter().
- *
- * Indicate that the 'page_bottom' region (in which the administration menu
- * is displayed) is an overlay supplemental region that should be refreshed
- * whenever its content is updated.
- *
- * @see toolbar_system_info_alter()
- */
-function admin_menu_system_info_alter(&$info, $file, $type) {
- if ($type == 'theme') {
- $info['overlay_supplemental_regions'][] = 'page_bottom';
- }
+ cache('admin_menu')->flush();
}
/**
@@ -157,10 +115,11 @@ function admin_menu_page_build(&$page) {
return;
}
// Performance: Skip this entirely for AJAX requests.
- if (strpos($_GET['q'], 'js/') === 0) {
+ if (backdrop_is_ajax()) {
return;
}
- global $user, $language;
+
+ global $user, $language_interface;
$path = drupal_get_path('module', 'admin_menu');
$page['page_bottom']['admin_menu'] = array(
@@ -173,12 +132,17 @@ function admin_menu_page_build(&$page) {
if ($user->uid == 1) {
$attached['css'][$path . '/admin_menu.uid1.css'] = $options;
}
- // Previous versions used the 'defer' attribute to increase browser rendering
- // performance. At least starting with Firefox 3.6, deferred .js files are
- // loaded, but Drupal.behaviors are not contained in the DOM when drupal.js
- // executes Drupal.attachBehaviors().
$attached['js'][$path . '/admin_menu.js'] = $options;
+ // Add current path to support menu item highlighting.
+ $args = explode('/', $_GET['q']);
+ if ($args[0] == 'admin' && !empty($args[1])) {
+ $settings['activeTrail'] = url($args[0] . '/' . $args[1]);
+ }
+ elseif (drupal_is_front_page()) {
+ $settings['activeTrail'] = url('<front>');
+ }
+
// Destination query strings are applied via JS.
$settings['destination'] = drupal_http_build_query(drupal_get_destination());
@@ -190,9 +154,10 @@ function admin_menu_page_build(&$page) {
// 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;
+ $cid = 'admin_menu:' . $user->uid . ':' . session_id() . ':' . $language_interface->langcode;
if (!$complete && !empty($_COOKIE['has_js']) && ($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
@@ -204,6 +169,7 @@ function admin_menu_page_build(&$page) {
}
// Otherwise, add the full menu to the page.
else {
+ module_load_include('inc', 'admin_menu');
$page['page_bottom']['admin_menu']['#markup'] = admin_menu_output($complete);
}
@@ -212,14 +178,11 @@ function admin_menu_page_build(&$page) {
$settings['replacements'] = $replacements;
}
- if ($setting = variable_get('admin_menu_margin_top', 1)) {
+ $config = config('admin_menu.settings');
+ if ($setting = $config->get('margin_top')) {
$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)) {
+ if ($setting = $config->get('position_fixed')) {
$settings['position_fixed'] = $setting;
// In fixed positioning, supply a callback function for tableheader.js to
@@ -230,15 +193,6 @@ function admin_menu_page_build(&$page) {
'type' => 'setting',
);
}
- if ($setting = variable_get('admin_menu_tweak_tabs', 0)) {
- $settings['tweak_tabs'] = $setting;
- }
- if ($_GET['q'] == 'admin/modules' || strpos($_GET['q'], 'admin/modules/list') === 0) {
- $settings['tweak_modules'] = variable_get('admin_menu_tweak_modules', 0);
- }
- if ($_GET['q'] == 'admin/people/permissions' || $_GET['q'] == 'admin/people/permissions/list') {
- $settings['tweak_permissions'] = variable_get('admin_menu_tweak_permissions', 0);
- }
$attached['js'][] = array(
'data' => array('admin_menu' => $settings),
@@ -276,7 +230,7 @@ function admin_menu_js() {
'cache' => array(
'callback' => 'admin_menu_js_cache',
'includes' => array('common', 'theme', 'unicode'),
- 'dependencies' => array('devel', 'filter', 'user'),
+ 'dependencies' => array('filter', 'user'),
),
);
}
@@ -296,11 +250,8 @@ function admin_menu_js() {
function admin_menu_cache_get($cid) {
$cache = &drupal_static(__FUNCTION__, array());
- if (!variable_get('admin_menu_cache_client', TRUE)) {
- return FALSE;
- }
if (!array_key_exists($cid, $cache)) {
- $cache[$cid] = cache_get($cid, 'cache_admin_menu');
+ $cache[$cid] = cache('admin_menu')->get($cid);
if ($cache[$cid] && isset($cache[$cid]->data)) {
$cache[$cid] = $cache[$cid]->data;
}
@@ -319,9 +270,7 @@ function admin_menu_cache_get($cid) {
* The cache ID of the data to retrieve.
*/
function admin_menu_cache_set($cid, $data) {
- if (variable_get('admin_menu_cache_client', TRUE)) {
- cache_set($cid, $data, 'cache_admin_menu');
- }
+ cache('admin_menu')->set($cid, $data);
}
/**
@@ -332,9 +281,6 @@ function admin_menu_cache_set($cid, $data) {
function admin_menu_js_cache() {
global $conf;
- // Suppress Devel module.
- $GLOBALS['devel_shutdown'] = FALSE;
-
// Enforce page caching.
$conf['cache'] = 1;
drupal_page_is_cacheable(TRUE);
@@ -366,6 +312,7 @@ function admin_menu_js_cache() {
drupal_add_http_header('Cache-Control', 'private, max-age=' . $max_age);
// Retrieve and return the rendered menu.
+ module_load_include('inc', 'admin_menu');
return admin_menu_output();
}
@@ -378,8 +325,8 @@ function admin_menu_deliver($page_callback_result) {
drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');
// Send appropriate language header for browsers.
- global $language;
- drupal_add_http_header('Content-Language', $language->language);
+ global $language_interface;
+ drupal_add_http_header('Content-Language', $language_interface->langcode);
// The page callback is always admin_menu_js_cache(), which always returns a
// string, and is only accessed when the user actually has access to it.
@@ -399,8 +346,8 @@ function admin_menu_admin_menu_replacements($complete) {
// current counts already.
if (!$complete) {
// Check whether the users count component is enabled.
- $components = variable_get('admin_menu_components', array());
- if (!empty($components['admin_menu.users']) && ($user_count = admin_menu_get_user_count())) {
+ $components = config_get('admin_menu.settings', 'components');
+ if (in_array('admin_menu.users', $components) && ($user_count = admin_menu_get_user_count())) {
// Replace the counters in the cached menu output with current counts.
$items['.admin-menu-users a'] = $user_count;
}
@@ -449,131 +396,19 @@ function admin_menu_session_count($timestamp = 0, $anonymous = TRUE) {
}
/**
- * Build the administration menu output.
- *
- * @param 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.
- */
-function admin_menu_output($complete = FALSE) {
- global $user, $language;
-
- $cache_server_enabled = !$complete && variable_get('admin_menu_cache_server', TRUE);
- $cid = 'admin_menu:' . $user->uid . ':' . session_id() . ':' . $language->language;
-
- // Try to load and output administration menu from server-side cache.
- // @todo Duplicates the page cache? Page cache ID contains the hash that is
- // generated at the bottom of this function, which is based on $content,
- // but logically identical to the $cid. Investigate whether not only the
- // cache_menu but also the cache_admin_menu could be dropped; the
- // client-side HTTP cache hash check could be based on a cid lookup in
- // cache_page instead? (i.e., one cache to rule them all) However,
- // cache_page is cleared very often.
- if ($cache_server_enabled) {
- $cache = cache_get($cid, 'cache_menu');
- 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 = variable_get('admin_menu_components', array());
- $components += array(
- 'admin_menu.menu' => TRUE,
- 'admin_menu.icon' => TRUE,
- 'admin_menu.account' => TRUE,
- );
- $content['#components'] = $components;
- $content['#complete'] = $complete;
-
- // Add site name as CSS class for development/staging theming 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-menu-site' . drupal_strtolower(preg_replace('/[^a-zA-Z0-9-]/', '-', $GLOBALS['cookie_domain']));
- // Displace overlay.
- // @see Drupal.overlay.create
- // @see toolbar_preprocess_toolbar()
- if (module_exists('overlay')) {
- $classes .= ' overlay-displace-top';
- }
- // @todo Always output container to harden JS-less support.
- $content['#prefix'] = '<div id="admin-menu" class="' . $classes . '"><div id="admin-menu-wrapper">';
- $content['#suffix'] = '</div></div>';
-
- // Load menu builder functions.
- module_load_include('inc', 'admin_menu');
-
- // @todo Move the below callbacks into hook_admin_menu_build()
- // implementations (and $module.admin_menu.inc).
-
- // Add administration menu.
- if (!empty($components['admin_menu.menu']) || $complete) {
- $content['menu'] = admin_menu_links_menu(admin_menu_tree('management'));
- $content['menu']['#theme'] = 'admin_menu_links';
- $content['menu']['#wrapper_attributes']['id'] = 'admin-menu-menu';
- // Ensure the menu tree is rendered between the icon and user links.
- $content['menu']['#weight'] = 0;
- }
-
- // Add menu additions.
- if (!empty($components['admin_menu.icon']) || $complete) {
- $content['icon'] = admin_menu_links_icon();
- }
- if (!empty($components['admin_menu.account']) || $complete) {
- $content['account'] = admin_menu_links_account();
- }
- if (!empty($components['admin_menu.users']) || $complete) {
- $content['users'] = admin_menu_links_users();
- }
- if (!empty($components['admin_menu.search']) || $complete) {
- $content['search'] = admin_menu_links_search();
- }
-
- // Allow modules to enhance the menu.
- // Uses '_output' suffix for consistency with the alter hook (see below).
- foreach (module_implements('admin_menu_output_build') as $module) {
- $function = $module . '_admin_menu_output_build';
- $function($content);
- }
-
- // Allow modules to alter the output.
- // The '_output' suffix is required to prevent hook implementation function
- // name clashes with the contributed Admin module.
- drupal_alter('admin_menu_output', $content);
-
- $content = drupal_render($content);
-
- // Cache the menu for this user.
- if ($cache_server_enabled) {
- cache_set($cid, $content, 'cache_menu');
- }
- }
-
- // Store the new hash for this user.
- if (!empty($_COOKIE['has_js']) && !$complete) {
- admin_menu_cache_set($cid, md5($content));
- }
-
- return $content;
-}
-
-/**
* Implements hook_admin_menu_output_build().
*/
function admin_menu_admin_menu_output_build(&$content) {
- if (!isset($content['menu'])) {
+ if (!isset($content['menu']['menu'])) {
return;
}
// Unassign weights for categories below Configuration.
// An alphabetical order is more natural for a dropdown menu.
- if (isset($content['menu']['admin/config'])) {
- foreach (element_children($content['menu']['admin/config']) as $key) {
- $content['menu']['admin/config'][$key]['#weight_original'] = $content['menu']['admin/config'][$key]['#weight'];
- unset($content['menu']['admin/config'][$key]['#weight']);
+ if (isset($content['menu']['menu']['admin/config'])) {
+ foreach (element_children($content['menu']['menu']['admin/config']) as $key) {
+ $content['menu']['menu']['admin/config'][$key]['#weight_original'] = $content['menu']['menu']['admin/config'][$key]['#weight'];
+ unset($content['menu']['menu']['admin/config'][$key]['#weight']);
}
}
@@ -593,14 +428,14 @@ function admin_menu_admin_menu_output_build(&$content) {
if (!empty($links)) {
// If the user has access to the top-level "Content" category, insert the
// "Add content" link tree there.
- if (isset($content['menu']['admin/content'])) {
- $content['menu']['admin/content'] += $links;
+ if (isset($content['menu']['menu']['admin/content'])) {
+ $content['menu']['menu']['admin/content'] += $links;
}
// Otherwise make insert "Add content" as top-level category.
else {
$key = key($links);
$links[$key]['#weight'] = -100;
- $content['menu'] += $links;
+ $content['menu']['menu'] += $links;
}
}
}
@@ -609,125 +444,12 @@ function admin_menu_admin_menu_output_build(&$content) {
* Implements hook_admin_menu_output_alter().
*/
function admin_menu_admin_menu_output_alter(&$content) {
- foreach ($content['menu'] as $key => $link) {
+ foreach ($content['menu']['menu'] as $key => $link) {
// Move local tasks on 'admin' into icon menu.
if ($key == 'admin/tasks' || $key == 'admin/index') {
- $content['icon']['icon'][$key] = $link;
- unset($content['menu'][$key]);
- }
- }
-}
-
-/**
- * Render a themed list of links.
- *
- * @param $variables
- * - elements: A renderable array of links using the following keys:
- * - #attributes: Optional array of attributes for the list item, processed
- * via drupal_attributes().
- * - #title: Title of the link, passed to l().
- * - #href: Optional path of the link, passed to l(). When omitted, the
- * element's '#title' is rendered without link.
- * - #description: Optional alternative text for the link, passed to l().
- * - #options: Optional alternative text for the link, passed to l().
- * The array key of each child element itself is passed as path for l().
- */
-function theme_admin_menu_links($variables) {
- $destination = &drupal_static('admin_menu_destination');
- $elements = $variables['elements'];
-
- if (!isset($destination)) {
- $destination = drupal_get_destination();
- $destination = $destination['destination'];
- }
-
- // The majority of items in the menu are sorted already, but since modules
- // may add or change arbitrary items anywhere, there is no way around sorting
- // everything again. element_sort() is not sufficient here, as it
- // intentionally retains the order of elements having the same #weight,
- // whereas menu links are supposed to be ordered by #weight and #title.
- uasort($elements, 'admin_menu_element_sort');
- $elements['#sorted'] = TRUE;
-
- $output = '';
- foreach (element_children($elements) as $path) {
- // Early-return nothing if user does not have access.
- if (isset($elements[$path]['#access']) && !$elements[$path]['#access']) {
- continue;
+ unset($content['menu']['menu'][$key]);
}
- $elements[$path] += array(
- '#attributes' => array(),
- '#options' => array(),
- );
- // Render children to determine whether this link is expandable.
- if (isset($elements[$path]['#type']) || isset($elements[$path]['#theme']) || isset($elements[$path]['#pre_render'])) {
- $elements[$path]['#children'] = drupal_render($elements[$path]);
- }
- else {
- $elements[$path]['#children'] = theme('admin_menu_links', array('elements' => $elements[$path]));
- if (!empty($elements[$path]['#children'])) {
- $elements[$path]['#attributes']['class'][] = 'expandable';
- }
- if (isset($elements[$path]['#attributes']['class'])) {
- $elements[$path]['#attributes']['class'] = $elements[$path]['#attributes']['class'];
- }
- }
-
- $link = '';
- // Handle menu links.
- if (isset($elements[$path]['#href'])) {
- // Strip destination query string from href attribute and apply a CSS class
- // for our JavaScript behavior instead.
- if (isset($elements[$path]['#options']['query']['destination']) && $elements[$path]['#options']['query']['destination'] == $destination) {
- unset($elements[$path]['#options']['query']['destination']);
- $elements[$path]['#options']['attributes']['class'][] = 'admin-menu-destination';
- }
-
- $link = l($elements[$path]['#title'], $elements[$path]['#href'], $elements[$path]['#options']);
- }
- // Handle plain text items, but do not interfere with menu additions.
- elseif (!isset($elements[$path]['#type']) && isset($elements[$path]['#title'])) {
- if (!empty($elements[$path]['#options']['html'])) {
- $title = $elements[$path]['#title'];
- }
- else {
- $title = check_plain($elements[$path]['#title']);
- }
- $attributes = '';
- if (isset($elements[$path]['#options']['attributes'])) {
- $attributes = drupal_attributes($elements[$path]['#options']['attributes']);
- }
- $link = '<span' . $attributes . '>' . $title . '</span>';
- }
-
- $output .= '<li' . drupal_attributes($elements[$path]['#attributes']) . '>';
- $output .= $link . $elements[$path]['#children'];
- $output .= '</li>';
}
- // @todo #attributes probably required for UL, but already used for LI.
- // @todo Use $element['#children'] here instead.
- if ($output) {
- $elements['#wrapper_attributes']['class'][] = 'dropdown';
- $attributes = drupal_attributes($elements['#wrapper_attributes']);
- $output = "\n" . '<ul' . $attributes . '>' . $output . '</ul>';
- }
- return $output;
-}
-
-/**
- * Function used by uasort to sort structured arrays by #weight AND #title.
- */
-function admin_menu_element_sort($a, $b) {
- // @see element_sort()
- $a_weight = isset($a['#weight']) ? $a['#weight'] : 0;
- $b_weight = isset($b['#weight']) ? $b['#weight'] : 0;
- if ($a_weight == $b_weight) {
- // @see element_sort_by_title()
- $a_title = isset($a['#title']) ? $a['#title'] : '';
- $b_title = isset($b['#title']) ? $b['#title'] : '';
- return strnatcasecmp($a_title, $b_title);
- }
- return ($a_weight < $b_weight) ? -1 : 1;
}
/**
@@ -737,19 +459,12 @@ function admin_menu_element_sort($a, $b) {
* as the current page path or the number of users.
*/
function admin_menu_translated_menu_link_alter(&$item, $map) {
- global $user, $base_url;
- static $access_all;
-
if ($item['menu_name'] != 'admin_menu') {
return;
}
- // Check whether additional development output is enabled.
- if (!isset($access_all)) {
- $access_all = variable_get('admin_menu_show_all', 0) && module_exists('devel');
- }
// Prepare links that would not be displayed normally.
- if ($access_all && !$item['access']) {
+ if (!$item['access']) {
$item['access'] = TRUE;
// Prepare for http://drupal.org/node/266596
if (!isset($item['localized_options'])) {
@@ -761,50 +476,19 @@ function admin_menu_translated_menu_link_alter(&$item, $map) {
if (!$item['access']) {
return;
}
-
- // Add developer information to all links, if enabled.
- if ($extra = variable_get('admin_menu_display', 0)) {
- $item['title'] .= ' ' . $extra[0] . ': ' . $item[$extra];
- }
}
/**
* Implements hook_flush_caches().
*
* Flushes client-side caches.
- *
- * @param int $uid
- * (optional) A user ID to limit the cache flush to.
*/
-function admin_menu_flush_caches($uid = NULL) {
- // A call to menu_rebuild() will trigger potentially thousands of calls into
- // menu_link_save(), for which admin_menu has to implement the corresponding
- // CRUD hooks, in order to take up any menu link changes, since any menu link
- // change could affect the admin menu (which essentially is an aggregate) and
- // since there is no other way to get notified about stale caches. The cache
- // only needs to be flushed once though, so we prevent a ton of needless
- // subsequent calls with this static.
- // @see http://drupal.org/node/918538
- $was_flushed = &drupal_static(__FUNCTION__, array());
- // $uid can be NULL. PHP automatically converts that into '' (empty string),
- // which is different to uid 0 (zero).
- if (isset($was_flushed[$uid])) {
- return;
- }
- $was_flushed[$uid] = TRUE;
-
- $cid = 'admin_menu:';
- if (isset($uid)) {
- $cid .= $uid . ':';
- }
- // Flush cached output of admin_menu.
- cache_clear_all($cid, 'cache_menu', TRUE);
+function admin_menu_flush_caches() {
// Flush client-side cache hashes.
drupal_static_reset('admin_menu_cache_get');
- // db_table_exists() required for SimpleTest.
- if (db_table_exists('cache_admin_menu')) {
- cache_clear_all(isset($uid) ? $cid : '*', 'cache_admin_menu', TRUE);
- }
+
+ // Flush cached output of admin_menu.
+ return array('cache_admin_menu');
}
/**
@@ -812,17 +496,17 @@ function admin_menu_flush_caches($uid = NULL) {
*/
function admin_menu_form_alter(&$form, &$form_state, $form_id) {
$global_flush_ids = array(
- 'admin_menu_theme_settings' => 1,
+ 'admin_menu_theme_settings',
// Update links for clean/non-clean URLs.
- 'system_clean_url_settings' => 1,
+ 'system_clean_url_settings',
// Incorporate changed user permissions.
- 'user_admin_permissions' => 1,
+ 'user_admin_permissions',
// Removing a role potentially means less permissions.
- 'user_admin_role_delete_confirm' => 1,
+ 'user_admin_role_delete_confirm',
// User name and roles may be changed on the user account form.
- 'user_profile_form' => 1,
+ 'user_profile_form',
);
- if (isset($global_flush_ids[$form_id])) {
+ if (in_array($form_id, $global_flush_ids)) {
$form['#submit'][] = 'admin_menu_form_alter_flush_cache_submit';
// Optionally limit the cache flush to a certain user ID.
@@ -844,15 +528,5 @@ function admin_menu_form_alter(&$form, &$form_state, $form_id) {
* Form submission handler to flush Administration menu caches.
*/
function admin_menu_form_alter_flush_cache_submit($form, &$form_state) {
- admin_menu_flush_caches($form_state['admin_menu_uid']);
-}
-
-/**
- * Implements hook_form_FORM_ID_alter().
- *
- * Extends Devel module with Administration menu developer settings.
- */
-function admin_menu_form_devel_admin_settings_alter(&$form, &$form_state) {
- form_load_include($form_state, 'inc', 'admin_menu');
- _admin_menu_form_devel_admin_settings_alter($form, $form_state);
+ cache('admin_menu')->flush();
}
diff --git a/admin_menu_toolbar/admin_menu_toolbar.info b/admin_menu_toolbar/admin_menu_toolbar.info
deleted file mode 100644
index 103e2c1..0000000
--- a/admin_menu_toolbar/admin_menu_toolbar.info
+++ /dev/null
@@ -1,5 +0,0 @@
-name = Administration menu Toolbar style
-description = A better Toolbar.
-package = Administration
-core = 7.x
-dependencies[] = admin_menu
diff --git a/admin_menu_toolbar/admin_menu_toolbar.install b/admin_menu_toolbar/admin_menu_toolbar.install
deleted file mode 100644
index bf067d7..0000000
--- a/admin_menu_toolbar/admin_menu_toolbar.install
+++ /dev/null
@@ -1,37 +0,0 @@
-<?php
-
-/**
- * @file
- * Installation functionality for Administration menu toolbar module.
- */
-
-/**
- * Implements hook_install().
- */
-function admin_menu_toolbar_install() {
- // Required to load JS/CSS in hook_init() after admin_menu.
- db_update('system')
- ->fields(array('weight' => 101))
- ->condition('type', 'module')
- ->condition('name', 'admin_menu_toolbar')
- ->execute();
-}
-
-/**
- * Set module weight to a value higher than admin_menu.
- *
- * At this point, admin_menu should have a weight of 100. To account for
- * customized weights, we increase the weight relatively.
- *
- * @see admin_menu_toolbar_install()
- */
-function admin_menu_toolbar_update_6300() {
- $weight = db_query("SELECT weight FROM {system} WHERE type = 'module' AND name = 'admin_menu'")->fetchField();
- $weight++;
- db_update('system')
- ->fields(array('weight' => $weight))
- ->condition('type', 'module')
- ->condition('name', 'admin_menu_toolbar')
- ->execute();
-}
-
diff --git a/tests/admin_menu.test b/tests/admin_menu.test
index 4b48c9a..38aa169 100644
--- a/tests/admin_menu.test
+++ b/tests/admin_menu.test
@@ -14,6 +14,7 @@ class AdminMenuWebTestCase extends DrupalWebTestCase {
protected $basePermissions = array(
'system' => 'access administration pages',
'admin_menu' => 'access administration menu',
+ 'node' => 'access content',
);
function setUp() {
@@ -21,10 +22,9 @@ class AdminMenuWebTestCase extends DrupalWebTestCase {
$modules = func_get_args();
$modules = isset($modules[0]) ? $modules[0] : $modules;
$modules[] = 'admin_menu';
+ $modules[] = 'node';
parent::setUp($modules);
- // Disable client-side caching.
- variable_set('admin_menu_cache_client', FALSE);
// Disable Clean URLs to ensure drupal.org testbot compatibility.
variable_set('clean_url', 0);
}
@@ -86,7 +86,7 @@ class AdminMenuWebTestCase extends DrupalWebTestCase {
$args[':title' . $i] = $title;
$message .= ($i ? ' » ' : '') . check_plain($title);
}
- $xpath = '//div[@id="admin-menu"]/div/ul' . implode('/parent::li/ul', $xpath);
+ $xpath = '//div[@id="admin-menu"]/div/ul/li/ul' . implode('/parent::li/ul', $xpath);
$this->assertElementByXPath($xpath, $args, $message . ' link found.');
}
@@ -114,14 +114,6 @@ class AdminMenuWebTestCase extends DrupalWebTestCase {
* Tests menu links depending on user permissions.
*/
class AdminMenuPermissionsTestCase extends AdminMenuWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Menu link access permissions',
- 'description' => 'Tests appearance of menu links depending on user permissions.',
- 'group' => 'Administration menu',
- );
- }
-
function setUp() {
parent::setUp(array('node'));
}
@@ -139,7 +131,6 @@ class AdminMenuPermissionsTestCase extends AdminMenuWebTestCase {
// Create a user who
// - can access content overview
- // - cannot access drupal.org links
// - cannot administer Contact module
$permissions = $this->basePermissions + array(
'access content overview',
@@ -150,22 +141,18 @@ class AdminMenuPermissionsTestCase extends AdminMenuWebTestCase {
// Check that the user can see the admin links, but not the drupal links.
$this->assertElementByXPath('//div[@id="admin-menu"]', array(), 'Administration menu found.');
$this->assertElementByXPath('//div[@id="admin-menu"]//a[contains(@href, :path)]', array(':path' => 'admin/content'), 'Content link found.');
- $this->assertNoElementByXPath('//div[@id="admin-menu"]//a[@href=:path]', array(':path' => 'http://drupal.org'), 'Icon » Drupal.org link not found.');
$this->assertNoElementByXPath('//div[@id="admin-menu"]//a[contains(@href, :path)]', array(':path' => 'admin/structure/contact'), 'Structure » Contact link not found.');
// Create a user "reversed" to the above; i.e., who
// - cannot access content overview
- // - can access drupal.org links
// - can administer Contact module
$permissions = $this->basePermissions + array(
- 'display drupal links',
'administer contact forms',
);
$admin_user2 = $this->drupalCreateUser($permissions);
$this->drupalLogin($admin_user2);
$this->assertElementByXPath('//div[@id="admin-menu"]', array(), 'Administration menu found.');
$this->assertNoElementByXPath('//div[@id="admin-menu"]//a[contains(@href, :path)]', array(':path' => 'admin/content'), 'Content link not found.');
- $this->assertElementByXPath('//div[@id="admin-menu"]//a[@href=:path]', array(':path' => 'http://drupal.org'), 'Icon » Drupal.org link found.');
$this->assertElementByXPath('//div[@id="admin-menu"]//a[contains(@href, :path)]', array(':path' => 'admin/structure/contact'), 'Structure » Contact link found.');
}
@@ -184,6 +171,7 @@ class AdminMenuPermissionsTestCase extends AdminMenuWebTestCase {
// Create a user with access to one configuration category.
$permissions = $this->basePermissions + array(
'administer users',
+ 'administer account settings',
);
$admin_user = $this->drupalCreateUser($permissions);
$this->drupalLogin($admin_user);
@@ -259,14 +247,6 @@ class AdminMenuPermissionsTestCase extends AdminMenuWebTestCase {
* Tests appearance, localization, and escaping of dynamic links.
*/
class AdminMenuDynamicLinksTestCase extends AdminMenuWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Dynamic links',
- 'description' => 'Tests appearance, localization, and escaping of dynamic links.',
- 'group' => 'Administration menu',
- );
- }
-
function setUp() {
parent::setUp(array('node'));
}
@@ -328,9 +308,7 @@ class AdminMenuDynamicLinksTestCase extends AdminMenuWebTestCase {
$type = $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
// Verify that "Add content" does not appear for unprivileged users.
- $permissions = $this->basePermissions + array(
- 'access content',
- );
+ $permissions = $this->basePermissions + array();
$this->web_user = $this->drupalCreateUser($permissions);
$this->drupalLogin($this->web_user);
$this->assertNoText(t('Add content'));
@@ -338,7 +316,6 @@ class AdminMenuDynamicLinksTestCase extends AdminMenuWebTestCase {
// Verify "Add content" appears below "Content" for administrative users.
$permissions = $this->basePermissions + array(
'access content overview',
- 'access content',
'create article content',
);
$this->admin_user = $this->drupalCreateUser($permissions);
@@ -350,7 +327,6 @@ class AdminMenuDynamicLinksTestCase extends AdminMenuWebTestCase {
// Verify "Add content" appears on the top-level for regular users.
$permissions = $this->basePermissions + array(
- 'access content',
'create article content',
);
$this->web_user = $this->drupalCreateUser($permissions);
@@ -365,16 +341,8 @@ class AdminMenuDynamicLinksTestCase extends AdminMenuWebTestCase {
* Tests appearance of different types of links.
*/
class AdminMenuLinkTypesTestCase extends AdminMenuWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Link types',
- 'description' => 'Tests appearance of different types of links.',
- 'group' => 'Administration menu',
- );
- }
-
function setUp() {
- parent::setUp(array('help'));
+ parent::setUp();
$permissions = module_invoke_all('permission');
$permissions = array_keys($permissions);
@@ -412,13 +380,6 @@ class AdminMenuLinkTypesTestCase extends AdminMenuWebTestCase {
// Verify that MENU_VISIBLE_IN_BREADCRUMB items (exact type) do NOT appear.
$this->assertNoLinkTrailByTitle(array(t('Modules'), t('Uninstall'), t('Uninstall')));
- $this->assertNoLinkTrailByTitle(array(t('Help'), 'admin_menu'));
-
- // Verify that special "Index" link appears below icon.
- $this->assertElementByXPath('//div[@id="admin-menu"]//a[contains(@href, :path) and text()=:title]', array(
- ':path' => 'admin/index',
- ':title' => t('Index'),
- ), "Icon » Index link found.");
}
}
@@ -426,14 +387,6 @@ class AdminMenuLinkTypesTestCase extends AdminMenuWebTestCase {
* Tests customized menu links.
*/
class AdminMenuCustomizedTestCase extends AdminMenuWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Customized links',
- 'description' => 'Tests customized menu links.',
- 'group' => 'Administration menu',
- );
- }
-
function setUp() {
parent::setUp(array('menu'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment