Commit a5e363a5 authored by alexpott's avatar alexpott

Issue #1978980 by dawehner: Convert toolbar_subtrees_jsonp() to a Controller.

parent 1e40d901
<?php
/**
* @file
* Contains \Drupal\toolbar\Access\SubtreeAccess.
*/
namespace Drupal\toolbar\Access;
use Drupal\Core\Access\AccessCheckInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
/**
* Defines a special access checker for the toolbar subtree route.
*/
class SubtreeAccess implements AccessCheckInterface {
/**
* {@inheritdoc}
*/
public function applies(Route $route) {
return array_key_exists('_access_toolbar_subtree', $route->getRequirements());
}
/**
* {@inheritdoc}
*/
public function access(Route $route, Request $request) {
$hash = $request->get('hash');
if (user_access('access toolbar') && ($hash == _toolbar_get_subtree_hash())) {
return TRUE;
}
else {
return NULL;
}
}
}
<?php
/**
* @file
* Contains \Drupal\toolbar\Routing\ToolbarController.
*/
namespace Drupal\toolbar\Routing;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
* Defines a controller for the toolbar module.
*/
class ToolbarController {
/**
* Returns the rendered subtree of each top-level toolbar link.
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function subtreesJsonp() {
_toolbar_initialize_page_cache();
$subtrees = toolbar_get_rendered_subtrees();
$response = new JsonResponse($subtrees);
$response->setCallback('Drupal.toolbar.setSubtrees');
return $response;
}
}
......@@ -59,20 +59,6 @@ function toolbar_theme($existing, $type, $theme, $path) {
return $items;
}
/**
* Implements hook_menu().
*/
function toolbar_menu() {
$items['toolbar/subtrees/%'] = array(
'page callback' => 'toolbar_subtrees_jsonp',
'page arguments' => array(2),
'access callback' => '_toolbar_subtrees_access',
'access arguments' => array(2),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implements hook_element_info().
*/
......@@ -125,28 +111,6 @@ function toolbar_element_info() {
return $elements;
}
/**
* Access callback: Returns if the user has access to the rendered subtree requested by the hash.
*
* @see toolbar_menu().
*/
function _toolbar_subtrees_access($hash) {
return user_access('access toolbar') && ($hash == _toolbar_get_subtree_hash());
}
/**
* Page callback: Returns the rendered subtree of each top-level toolbar link.
*
* @see toolbar_menu().
*/
function toolbar_subtrees_jsonp($hash) {
_toolbar_initialize_page_cache();
$subtrees = toolbar_get_rendered_subtrees();
$response = new JsonResponse($subtrees);
$response->setCallback('Drupal.toolbar.setSubtrees');
return $response;
}
/**
* Use Drupal's page cache for toolbar/subtrees/*, even for authenticated users.
*
......
toolbar_subtrees:
pattern: '/toolbar/subtrees/{hash}'
defaults:
_controller: '\Drupal\toolbar\Routing\ToolbarController::subtreesJsonp'
requirements:
_access_toolbar_subtree: 'TRUE'
services:
access_check.toolbar_subtree:
class: Drupal\toolbar\Access\SubtreeAccess
tags:
- { name: access_check }
cache.toolbar:
class: Drupal\Core\Cache\CacheBackendInterface
tags:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment