You are here

protected function WebprofilerEventSubscriber::injectToolbar in Devel 8

Same name and namespace in other branches
  1. 8.3 webprofiler/src/EventSubscriber/WebprofilerEventSubscriber.php \Drupal\webprofiler\EventSubscriber\WebprofilerEventSubscriber::injectToolbar()
  2. 8.2 webprofiler/src/EventSubscriber/WebprofilerEventSubscriber.php \Drupal\webprofiler\EventSubscriber\WebprofilerEventSubscriber::injectToolbar()
  3. 4.x webprofiler/src/EventSubscriber/WebprofilerEventSubscriber.php \Drupal\webprofiler\EventSubscriber\WebprofilerEventSubscriber::injectToolbar()

Parameters

\Symfony\Component\HttpFoundation\Response $response:

1 call to WebprofilerEventSubscriber::injectToolbar()
WebprofilerEventSubscriber::onKernelResponse in webprofiler/src/EventSubscriber/WebprofilerEventSubscriber.php

File

webprofiler/src/EventSubscriber/WebprofilerEventSubscriber.php, line 71

Class

WebprofilerEventSubscriber
Class WebprofilerEventSubscriber

Namespace

Drupal\webprofiler\EventSubscriber

Code

protected function injectToolbar(Response $response) {
  $content = $response
    ->getContent();
  $pos = mb_strripos($content, '</body>');
  if (FALSE !== $pos) {
    if ($token = $response->headers
      ->get('X-Debug-Token')) {
      $loader = [
        '#theme' => 'webprofiler_loader',
        '#token' => $token,
        '#profiler_url' => $this->urlGenerator
          ->generate('webprofiler.toolbar', [
          'profile' => $token,
        ]),
      ];
      $content = mb_substr($content, 0, $pos) . $this->renderer
        ->renderRoot($loader) . mb_substr($content, $pos);
      $response
        ->setContent($content);
    }
  }
}