Skip to content
Snippets Groups Projects
Commit 6fe99996 authored by Jürgen Haas's avatar Jürgen Haas
Browse files

Issue #3326270 by jurgenhaas: Support webprofiler version 10

parent e9faf59a
No related branches found
Tags 11.4.0-alpha2
No related merge requests found
......@@ -8,4 +8,4 @@ services:
class: Drupal\eca_ui\DataCollector\EcaDataCollector
arguments: ['@logger.channel.eca']
tags:
- { name: data_collector, template: '@eca_ui/Collector/eca.html.twig', id: 'eca', title: 'ECA', priority: 12 }
- { name: data_collector, template: '@eca_ui/Collector/eca.html.twig', id: 'eca', label: 'ECA', title: 'ECA', priority: 12 }
......@@ -2,9 +2,7 @@
namespace Drupal\eca_ui\DataCollector;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\eca\ConfigurableLoggerChannel;
use Drupal\webprofiler\DataCollector\DrupalDataCollectorTrait;
use Drupal\webprofiler\DrupalDataCollectorInterface;
use Symfony\Component\HttpFoundation\Request;
......@@ -16,69 +14,13 @@ use Symfony\Component\HttpKernel\DataCollector\DataCollector;
*/
class EcaDataCollector extends DataCollector implements DrupalDataCollectorInterface {
use StringTranslationTrait, DrupalDataCollectorTrait;
/**
* The logger channel.
*
* @var \Drupal\eca\ConfigurableLoggerChannel
*/
protected ConfigurableLoggerChannel $logger;
/**
* EcaDataCollector constructor.
*
* @param \Drupal\eca\ConfigurableLoggerChannel $logger
* The logger channel.
*/
public function __construct(ConfigurableLoggerChannel $logger) {
$this->logger = $logger;
}
use StringTranslationTrait, DrupalDataCollectorTrait, EcaDataCollectorTrait;
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response): void {
foreach ($this->logger->getDataCurrentRequest() as $item) {
foreach ($item[2] as $key => $value) {
$item[2][$key] = strip_tags((string) (new FormattableMarkup($value, $item[3])));
}
$this->data[] = [
'message' => $item[1],
'tokens' => implode('<br>', $item[2]),
];
}
}
/**
* Gets the number of log entries.
*
* @return string
* The number of log entries.
*/
public function getNumberOfLogEntries(): string {
return count($this->data);
}
/**
* {@inheritdoc}
*/
public function getName(): string {
return 'eca';
}
/**
* {@inheritdoc}
*/
public function getTitle(): string {
return $this->t('ECA');
}
/**
* {@inheritdoc}
*/
public function getIcon(): string {
return 'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAADv0lEQVRYR+1We0jTURT+5qMUH5SaJmlZWpLVEBMyk9R8oM00DQyKpGKRJkX2gJ6GQUWlaZYaZKQzzYZEZEZpOdHAZWkKim8zWkqUbysycZ17aWubGhVB/+zA/vide8/jfuec70xglJSkxH8UgT4BPQJ6BPQITIXAER8fWJuaqulJqVTiWm0tugYGuM5l9mycCQiAs5UV/x748gWp1dV42NHBv81nzMA2oRCZL15AIBD8kuYmEZEhGXw6fhzSpiYMf/3KjRlVXn3+HK19fTAxNERTfDwqurvxoL2dDpVwpoQS/fywLicHL3t7sXXFCtzcuBFL0tPRPTT0dwksy8hA548Xa3rwd3KCJCoK81NTKfZPFs+hgIrhYZwoL0dRdDTCXV1x6PFjpNfU/NsE1i9ejItBQViWmanlOC0kBOMTEzglk6Hn4EHca2mBg6UlAiSSP0vAyMAAo8eOQZiVhTaCXFdElEBycDDcCCHNLeZmY8OvLp0zB+cCAxFy6xYvlWNKCj5Sj0wnWj3A2iVLJMIODw9UvXmDiNu38enbN7Vt4KJFKNi0CbNMTFBHtRbl56NPx3leZCR6R0ZwuKwMr2JjcVkuR25Dw+8lwIIHOzsj6s4dpIeGcqOyzk61sXjlSu4wu64OdzdvhlyhwEmCXCUzqUEZ/GEFBaims0RfX7jb2SFKKuVXVjs4YI2jI5JpYlSiRoC9viEuDh39/Ygmg1PU1bs9PVGqSoAaLowaK7KwEDKagAxKUEDl2lNSona23sUFWRs2wIk1KGlZ8MqdO2GfnMyRXGJtDdn27ZDU1+Po06fcTqsEdmZmeBITgwkKNtfCAqFURwa1Sk77+0NM5XlFOp8FCxCUm4uanh71+XUK7rdwIcq7utS6GHd3lLS14f3oKNe5Uq+sJdukigqcqarSToBdsDc3R3dCAkLy8vhLdeWwtzf2eXnx4C0aTcr44x3BX9zaig+fP3MzA/qtItjZNNxtbuY6D3t7+NIoJzx6hAxGVLpMqCKi6XhgujFcR07zqUEdL13CuAY/+NJrpcQL86gMy6kkDOGzlZVIoT5gLPnHCQQQxDciIuCUlqYFzhXqCRMjI+wqLtbSswcpCJmtRUXop4kRUhJsKlQUPW0C4vv3+Tip5PXgIN8F5sbGaNm7l1P1Q6JixoaMii8QN4TRWD57+3ZS2bLDwzE6Nob9BLuuTEqATYNcLIaVxjJiRqy2B0pLub3Q1hbniQ3ZMmL32TJikBY2Nk65fBh9b6H9oIsO86X/V6xHQI+AHoH/jsB3PoCy0Nz5DDgAAAAASUVORK5CYII=';
$this->doCollect();
}
}
<?php
namespace Drupal\eca_ui\DataCollector;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\webprofiler\DataCollector\DataCollectorTrait;
use Drupal\webprofiler\DataCollector\HasPanelInterface;
use Drupal\webprofiler\DataCollector\PanelTrait;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
/**
* Provides EcaDataCollector for the webprofiler of devel.
*/
class EcaDataCollector10 extends DataCollector implements HasPanelInterface {
use StringTranslationTrait, DataCollectorTrait, EcaDataCollectorTrait, PanelTrait;
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Throwable $exception = null): void {
$this->doCollect();
}
/**
* {@inheritdoc}
*/
public function reset() {
$this->data = [];
}
/**
* {@inheritdoc}
*/
public function getPanel(): array {
if (empty($this->data)) {
return [
'#markup' => $this->t('No debugging data available.')
];
}
$rows = [];
foreach ($this->data as $data) {
$rows[] = [
[
'data' => $data['message'],
'class' => 'webprofiler__key',
],
[
'data' => [
'#type' => 'inline_template',
'#template' => '{{ data|raw }}',
'#context' => [
'data' => $data['tokens'],
],
],
'class' => 'webprofiler__value',
],
];
}
return [
'Debugging' => [
'#theme' => 'webprofiler_dashboard_section',
'#title' => 'Debugging',
'#data' => [
'#type' => 'table',
'#header' => [$this->t('Step'), $this->t('Tokens')],
'#rows' => $rows,
'#attributes' => [
'class' => [
'webprofiler__table',
],
],
],
],
];
}
}
<?php
namespace Drupal\eca_ui\DataCollector;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\eca\ConfigurableLoggerChannel;
trait EcaDataCollectorTrait {
/**
* The logger channel.
*
* @var \Drupal\eca\ConfigurableLoggerChannel
*/
protected ConfigurableLoggerChannel $logger;
/**
* EcaDataCollector constructor.
*
* @param \Drupal\eca\ConfigurableLoggerChannel $logger
* The logger channel.
*/
public function __construct(ConfigurableLoggerChannel $logger) {
$this->logger = $logger;
}
/**
* Gets the number of log entries.
*
* @return string
* The number of log entries.
*/
public function getNumberOfLogEntries(): string {
return count($this->data);
}
/**
* {@inheritdoc}
*/
public function getName(): string {
return 'eca';
}
/**
* {@inheritdoc}
*/
public function getTitle(): string {
return $this->t('ECA');
}
/**
* {@inheritdoc}
*/
public function getIcon(): string {
return 'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAADv0lEQVRYR+1We0jTURT+5qMUH5SaJmlZWpLVEBMyk9R8oM00DQyKpGKRJkX2gJ6GQUWlaZYaZKQzzYZEZEZpOdHAZWkKim8zWkqUbysycZ17aWubGhVB/+zA/vide8/jfuec70xglJSkxH8UgT4BPQJ6BPQITIXAER8fWJuaqulJqVTiWm0tugYGuM5l9mycCQiAs5UV/x748gWp1dV42NHBv81nzMA2oRCZL15AIBD8kuYmEZEhGXw6fhzSpiYMf/3KjRlVXn3+HK19fTAxNERTfDwqurvxoL2dDpVwpoQS/fywLicHL3t7sXXFCtzcuBFL0tPRPTT0dwksy8hA548Xa3rwd3KCJCoK81NTKfZPFs+hgIrhYZwoL0dRdDTCXV1x6PFjpNfU/NsE1i9ejItBQViWmanlOC0kBOMTEzglk6Hn4EHca2mBg6UlAiSSP0vAyMAAo8eOQZiVhTaCXFdElEBycDDcCCHNLeZmY8OvLp0zB+cCAxFy6xYvlWNKCj5Sj0wnWj3A2iVLJMIODw9UvXmDiNu38enbN7Vt4KJFKNi0CbNMTFBHtRbl56NPx3leZCR6R0ZwuKwMr2JjcVkuR25Dw+8lwIIHOzsj6s4dpIeGcqOyzk61sXjlSu4wu64OdzdvhlyhwEmCXCUzqUEZ/GEFBaims0RfX7jb2SFKKuVXVjs4YI2jI5JpYlSiRoC9viEuDh39/Ygmg1PU1bs9PVGqSoAaLowaK7KwEDKagAxKUEDl2lNSona23sUFWRs2wIk1KGlZ8MqdO2GfnMyRXGJtDdn27ZDU1+Po06fcTqsEdmZmeBITgwkKNtfCAqFURwa1Sk77+0NM5XlFOp8FCxCUm4uanh71+XUK7rdwIcq7utS6GHd3lLS14f3oKNe5Uq+sJdukigqcqarSToBdsDc3R3dCAkLy8vhLdeWwtzf2eXnx4C0aTcr44x3BX9zaig+fP3MzA/qtItjZNNxtbuY6D3t7+NIoJzx6hAxGVLpMqCKi6XhgujFcR07zqUEdL13CuAY/+NJrpcQL86gMy6kkDOGzlZVIoT5gLPnHCQQQxDciIuCUlqYFzhXqCRMjI+wqLtbSswcpCJmtRUXop4kRUhJsKlQUPW0C4vv3+Tip5PXgIN8F5sbGaNm7l1P1Q6JixoaMii8QN4TRWD57+3ZS2bLDwzE6Nob9BLuuTEqATYNcLIaVxjJiRqy2B0pLub3Q1hbniQ3ZMmL32TJikBY2Nk65fBh9b6H9oIsO86X/V6xHQI+AHoH/jsB3PoCy0Nz5DDgAAAAASUVORK5CYII=';
}
protected function doCollect(): void {
foreach ($this->logger->getDataCurrentRequest() as $item) {
foreach ($item[2] as $key => $value) {
$item[2][$key] = strip_tags((string) (new FormattableMarkup($value, $item[3])));
}
$this->data[] = [
'message' => $item[1],
'tokens' => implode('<br>', $item[2]),
];
}
}
}
<?php
namespace Drupal\eca_ui;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceProviderBase;
use Drupal\eca_ui\DataCollector\EcaDataCollector10;
/**
* Provider for dynamically provided services by ECA UI.
*/
class EcaUiServiceProvider extends ServiceProviderBase {
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container): void {
if (interface_exists('Drupal\webprofiler\DataCollector\TemplateAwareDataCollectorInterface')) {
$definition = $container->getDefinition('webprofiler.eca_ui');
$definition->setClass(EcaDataCollector10::class);
$tags = $definition->getTags();
$tags['data_collector'][0]['template'] = '@eca_ui/Collector/eca10.html.twig';
$definition->setTags($tags);
}
}
}
{% block toolbar %}
{% set status = 'green' %}
{% set icon %}
{{ include('@eca_ui/Icon/logo.svg') }}
{% endset %}
{% set text %}
<div class="sf-toolbar-info-piece">
<b>Log entries</b>
<span>{{ collector.numberoflogentries }}</span>
</div>
<div class="sf-toolbar-info-piece">
<b>Token</b>
<span>{{ token }}</span>
</div>
{% endset %}
{{ include('@webprofiler/Profiler/toolbar_item.html.twig', { link: profiler_url, status: status|default('') }) }}
{% endblock %}
{% block panel %}
{{ collector.panel() }}
{% endblock %}
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 26.2.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Ebene_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 250 250" style="enable-background:new 0 0 250 250;" xml:space="preserve">
<style type="text/css">
.st0{fill:#098282;}
.st1{fill:none;stroke:#FFFFFF;stroke-width:9;stroke-linecap:round;stroke-linejoin:round;}
.st2{fill:#098282;stroke:#FFFFFF;stroke-width:9;stroke-linecap:round;stroke-linejoin:round;}
</style>
<g>
<g>
<rect class="st0" width="250" height="250"/>
</g>
<g>
<path class="st1" d="M79.3,174H43.4V78.2h33h-33v47.3h50h-50V174H79.3z"/>
<path class="st1" d="M146.9,164.2c-0.8,2-2,3.6-3.4,5.1c-1.4,1.4-3.1,2.6-5,3.4c-1.9,0.8-4,1.3-6.2,1.3h-12.9
c-2.2,0-4.3-0.4-6.2-1.3c-1.9-0.8-3.6-2-5-3.4c-1.4-1.4-2.6-3.1-3.4-5.1c-0.8-2-1.3-4-1.3-6.3V92.3c0-2.2,0.4-4.3,1.3-6.3
c0.8-2,2-3.7,3.4-5.2c1.4-1.5,3.1-2.6,5-3.5c1.9-0.8,4-1.3,6.2-1.3h12.9c2.2,0,4.3,0.4,6.2,1.3c1.9,0.8,3.6,2,5,3.5
c1.4,1.5,2.6,3.2,3.4,5.2c0.8,2,1.3,4.1,1.3,6.3v7.9v-7.9c0-2.2-0.4-4.3-1.3-6.3c-0.8-2-2-3.7-3.4-5.2c-1.4-1.5-3.1-2.6-5-3.5
c-1.9-0.8-4-1.3-6.2-1.3h-12.9c-2.2,0-4.3,0.4-6.2,1.3c-1.9,0.8-3.6,2-5,3.5c-1.4,1.5-2.6,3.2-3.4,5.2c-0.8,2-1.3,4.1-1.3,6.3V158
c0,2.2,0.4,4.3,1.3,6.3c0.8,2,2,3.6,3.4,5.1c1.4,1.4,3.1,2.6,5,3.4c1.9,0.8,4,1.3,6.2,1.3h12.9c2.2,0,4.3-0.4,6.2-1.3
c1.9-0.8,3.6-2,5-3.4C144.9,167.9,146.1,166.2,146.9,164.2"/>
<rect x="32.3" y="114.7" transform="matrix(0.7072 -0.7071 0.7071 0.7072 -76.3609 67.7618)" class="st2" width="22.7" height="22.7"/>
<path class="st2" d="M117.5,126.1c0,7.5-6.1,13.6-13.6,13.6c-7.5,0-13.6-6.1-13.6-13.6c0-7.5,6.1-13.6,13.6-13.6
C111.5,112.5,117.5,118.6,117.5,126.1z"/>
<g>
<path class="st1" d="M146.9,164.2l27.7-85.9l30,95.7l-30-95.7"/>
<polyline class="st1" points="219.4,124 235.4,140 219.4,156.1 "/>
<path class="st1" d="M154.7,140.1l77.1,0.1l-62.2-0.1"/>
</g>
</g>
</g>
</svg>
......@@ -119,8 +119,10 @@ class ConfigurableLoggerChannel extends LoggerChannel {
if (!isset($this->webprofilerEnabled)) {
$this->webprofilerEnabled = FALSE;
if ($this->moduleHandler->moduleExists('webprofiler')) {
$items = $this->configFactory->get('webprofiler.config')->get('active_toolbar_items');
$this->webprofilerEnabled = (bool) ($items['eca'] ?? FALSE);
if (($items = $this->configFactory->get('webprofiler.config')->get('active_toolbar_items')) ||
($items = $this->configFactory->get('webprofiler.settings')->get('active_toolbar_items'))) {
$this->webprofilerEnabled = (bool) ($items['eca'] ?? FALSE);
}
}
}
return $this->webprofilerEnabled;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment