From 205561486c01bb580d11465e081ee0003e21b9f5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=2E=20Rene=CC=81e=20Beach?= <splendidnoise@gmail.com>
Date: Mon, 3 Feb 2014 00:17:16 -0500
Subject: [PATCH] Issue #2187483 by jessebeach: JsonResponse->callback now
 returns data in an Insert Command without any support in ajax.js to eval the
 callback in the client.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: J. Renée Beach <splendidnoise@gmail.com>
---
 core/modules/toolbar/js/views/ToolbarVisualView.js | 17 ++++++++++++++++-
 core/modules/toolbar/toolbar.module                |  1 +
 core/modules/toolbar/toolbar.routing.yml           |  2 +-
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/core/modules/toolbar/js/views/ToolbarVisualView.js b/core/modules/toolbar/js/views/ToolbarVisualView.js
index 10c762d..0be8af7 100644
--- a/core/modules/toolbar/js/views/ToolbarVisualView.js
+++ b/core/modules/toolbar/js/views/ToolbarVisualView.js
@@ -263,7 +263,22 @@
           localStorage.removeItem('Drupal.toolbar.subtrees');
           // The response from the server will call the resolve method of the
           // Drupal.toolbar.setSubtrees Promise.
-          $.ajax(endpoint);
+          var element = document.getElementById('toolbar-administration');
+          var ajax = new Drupal.ajax('toolbar-administration', document.getElementById('toolbar-administration'), {
+            url: endpoint,
+            event: 'subtrees.toolbar',
+            wrapper: 'toolbar-administration',
+            progress: {
+              type: null
+            }
+          });
+          // Eval the JSON response to invoke the callback.
+          ajax.commands.insert = function (ajax, response) {
+            if (response.data) {
+              eval(response.data);
+            }
+          }
+          $(ajax.element).trigger(ajax.element_settings.event);
           // Cache the hash for the subtrees locally.
           localStorage.setItem('Drupal.toolbar.subtreesHash', subtreesHash);
         }
diff --git a/core/modules/toolbar/toolbar.module b/core/modules/toolbar/toolbar.module
index d91527b..dbce786 100644
--- a/core/modules/toolbar/toolbar.module
+++ b/core/modules/toolbar/toolbar.module
@@ -525,6 +525,7 @@ function toolbar_library_info() {
       array('system', 'jquery'),
       array('system', 'drupal'),
       array('system', 'drupalSettings'),
+      array('system', 'drupal.ajax'),
       array('system', 'drupal.announce'),
       array('system', 'backbone'),
       array('system', 'matchmedia'),
diff --git a/core/modules/toolbar/toolbar.routing.yml b/core/modules/toolbar/toolbar.routing.yml
index 2e1e4cd..6e2f255 100644
--- a/core/modules/toolbar/toolbar.routing.yml
+++ b/core/modules/toolbar/toolbar.routing.yml
@@ -3,4 +3,4 @@ toolbar.subtrees:
   defaults:
     _controller: '\Drupal\toolbar\Controller\ToolbarController::subtreesJsonp'
   requirements:
-    _custom_access: '\Drupal\toolbar\Routing\ToolbarController::checkSubTreeAccess'
+    _custom_access: '\Drupal\toolbar\Controller\ToolbarController::checkSubTreeAccess'
-- 
1.8.2

