/**
  * 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.resolve');
     return $response;
 }
Example #2
0
 /**
  * Returns an AJAX response to render the toolbar subtrees.
  *
  * @return \Drupal\Core\Ajax\AjaxResponse
  */
 public function subtreesAjax()
 {
     list($subtrees, $cacheability) = toolbar_get_rendered_subtrees();
     $response = new AjaxResponse();
     $response->addCommand(new SetSubtreesCommand($subtrees));
     // The Expires HTTP header is the heart of the client-side HTTP caching. The
     // additional server-side page cache only takes effect when the client
     // accesses the callback URL again (e.g., after clearing the browser cache
     // or when force-reloading a Drupal page).
     $max_age = 365 * 24 * 60 * 60;
     $response->setPrivate();
     $response->setMaxAge($max_age);
     $expires = new \DateTime();
     $expires->setTimestamp(REQUEST_TIME + $max_age);
     $response->setExpires($expires);
     return $response;
 }