ToolbarController.php in Devel 8.3
File
webprofiler/src/Controller/ToolbarController.php
View source
<?php
namespace Drupal\webprofiler\Controller;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Render\RendererInterface;
use Drupal\webprofiler\Profiler\Profiler;
use Drupal\webprofiler\Profiler\TemplateManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Profiler\Profile;
class ToolbarController extends ControllerBase {
private $profiler;
private $templateManager;
private $renderer;
public static function create(ContainerInterface $container) {
return new static($container
->get('profiler'), $container
->get('template_manager'), $container
->get('renderer'));
}
public function __construct(Profiler $profiler, TemplateManager $templateManager, RendererInterface $renderer) {
$this->profiler = $profiler;
$this->templateManager = $templateManager;
$this->renderer = $renderer;
}
public function toolbarAction(Profile $profile) {
$this->profiler
->disable();
$templates = $this->templateManager
->getTemplates($profile);
$rendered = '';
foreach ($templates as $name => $template) {
$rendered .= $template
->renderBlock('toolbar', [
'collector' => $profile
->getcollector($name),
'token' => $profile
->getToken(),
'name' => $name,
]);
}
$toolbar = [
'#theme' => 'webprofiler_toolbar',
'#toolbar' => $rendered,
'#token' => $profile
->getToken(),
];
return new Response($this->renderer
->render($toolbar));
}
public function savePerformanceTimingAction(Profile $profile, Request $request) {
$this->profiler
->disable();
$data = Json::decode($request
->getContent());
$collector = $profile
->getCollector('performance_timing');
$collector
->setData($data);
$this->profiler
->updateProfile($profile);
return new JsonResponse([
'success' => TRUE,
]);
}
}