function 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);
        }
    }
}