From d69994859c0c57bf5d02b6e91e7c742953bde526 Mon Sep 17 00:00:00 2001 From: Mark Carver Date: Mon, 17 Mar 2014 08:51:21 -0500 Subject: [PATCH] Issue #2219467 by Mark Carver: Change API implementation for JS 7.x-2.x. --- admin_menu.js | 5 +++++ admin_menu.module | 27 +++++++++++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/admin_menu.js b/admin_menu.js index de0bb90..363bdbd 100644 --- a/admin_menu.js +++ b/admin_menu.js @@ -127,6 +127,11 @@ Drupal.admin.getCache = function (hash, onSuccess) { dataType: 'text', // Prevent auto-evaluation of response. global: false, // Do not trigger global AJAX events. url: Drupal.settings.admin_menu.basePath.replace(/admin_menu/, 'js/admin_menu/cache/' + hash), + data: { + js_module: 'admin_menu', + js_callback: 'cache', + js_token: Drupal.settings.js && Drupal.settings.js.tokens && Drupal.settings.js.tokens['admin_menu-cache'] || '' + }, success: onSuccess, complete: function (XMLHttpRequest, status) { Drupal.admin.hashes.hash = status; diff --git a/admin_menu.module b/admin_menu.module index 8a8dee1..84bcbb0 100644 --- a/admin_menu.module +++ b/admin_menu.module @@ -64,7 +64,7 @@ function admin_menu_menu() { // AJAX callback. // @see http://drupal.org/project/js $items['js/admin_menu/cache'] = array( - 'page callback' => 'admin_menu_js_cache', + 'page callback' => 'admin_menu_js_callback_cache', 'delivery callback' => 'admin_menu_deliver', 'access arguments' => array('access administration menu'), 'type' => MENU_CALLBACK, @@ -192,6 +192,11 @@ function admin_menu_page_build(&$page) { // user, only output the hash for the client-side HTTP cache callback URL. $cid = 'admin_menu:' . $user->uid . ':' . session_id() . ':' . $language->language; if (!$complete && !empty($_COOKIE['has_js']) && ($hash = admin_menu_cache_get($cid))) { + // If the JS module is installed, invoke the function to generate a token + // so it is added via settings. + if (module_exists('js')) { + js_get_token('admin_menu', 'cache'); + } $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 @@ -269,14 +274,15 @@ function admin_menu_suppress($set = TRUE) { } /** - * Implements hook_js(). + * Implements hook_js_info(). */ -function admin_menu_js() { +function admin_menu_js_info() { return array( 'cache' => array( - 'callback' => 'admin_menu_js_cache', - 'includes' => array('common', 'theme', 'unicode'), + 'delivery callback' => 'admin_menu_deliver', 'dependencies' => array('devel', 'filter', 'user'), + 'includes' => array('common', 'theme', 'unicode'), + 'methods' => array('GET'), ), ); } @@ -329,7 +335,7 @@ function admin_menu_cache_set($cid, $data) { * * @see admin_menu_deliver() */ -function admin_menu_js_cache() { +function admin_menu_js_callback_cache() { global $conf; // Suppress Devel module. @@ -372,7 +378,7 @@ function admin_menu_js_cache() { /** * Delivery callback for client-side HTTP caching. * - * @see admin_menu_js_cache() + * @see admin_menu_js_callback_cache() */ function admin_menu_deliver($page_callback_result) { drupal_add_http_header('Content-Type', 'text/html; charset=utf-8'); @@ -381,9 +387,10 @@ function admin_menu_deliver($page_callback_result) { global $language; drupal_add_http_header('Content-Language', $language->language); - // 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. - // Therefore, we do not care for the other possible page callback results. + // The page callback is always admin_menu_js_callback_cache(), which always + // returns a string, and is only accessed when the user actually has access + // to it. Therefore, we do not care for the other possible page callback + // results. print $page_callback_result; // Perform end-of-request tasks. The page cache is created here. -- 1.8.5.3