SetSubtreesCommand example


class ToolbarController extends ControllerBase implements TrustedCallbackInterface {

  /** * Returns an AJAX response to render the toolbar subtrees. * * @return \Drupal\Core\Ajax\AjaxResponse */
  public function subtreesAjax() {
    [$subtrees] = 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);
    
Home | Imprint | This part of the site doesn't use cookies.