Skip to content
Snippets Groups Projects
Commit 05c3a05e authored by Julian Pustkuchen's avatar Julian Pustkuchen
Browse files

Merge branch 'revert-98ba882a' into '2.0.x'

Revert "Issue #3373694: Fix the issues reported by phpcs" partially

See merge request !10
parents 98ba882a cf7c4461
No related branches found
No related tags found
No related merge requests found
Pipeline #277046 passed with warnings
......@@ -5,50 +5,47 @@
* Devel debug log module install/schema hooks.
*/
/**
* {@inheritdoc}
*/
function devel_debug_log_schema() {
$schema = [];
$schema = array();
$schema['devel_debug_log'] = [
$schema['devel_debug_log'] = array(
'description' => 'Table for storing debug messages.',
'fields' => [
'id' => [
'fields' => array(
'id' => array(
'description' => 'The message identifier.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
],
'timestamp' => [
),
'timestamp' => array(
'description' => 'The Unix timestamp when the message was saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
'title' => [
),
'title' => array(
'description' => 'The title of the debug message.',
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
],
'message' => [
),
'message' => array(
'description' => 'The debug message.',
'type' => 'text',
'size' => 'big',
'not null' => TRUE,
],
'serialized' => [
),
'serialized' => array(
'description' => 'Indicates whether the message is serialized.',
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 0,
],
],
'primary key' => ['id'],
];
),
),
'primary key' => array('id'),
);
return $schema;
}
......@@ -2,4 +2,4 @@ devel_debug_log.list:
title: Debug messages
description: 'List debug messages.'
route_name: devel_debug_log.list
parent: system.admin_reports
parent: system.admin_reports
\ No newline at end of file
......@@ -12,56 +12,54 @@ use Kint\Renderer\RichRenderer;
* Saves a debug message.
*
* @param mixed $message
* A debug message to save, which can be:
* A debug message to save, which can be:
* - string: saved as it is;
* - object/array: serialized before saving;
*
* Currently, there's development going on regarding the serialization part,
* since most of the data in D8 contains references to injected services and
* maybe even plugins.
* A discussion about this topic can be found here:.
* @param string $title
* Title of the debug message.
* Currently, there's development going on regarding the serialization part,
* since most of the data in D8 contains references to injected services and
* maybe even plugins.
* A discussion about this topic can be found here:
* @see https://www.drupal.org/node/2705731
*
* @see https://www.drupal.org/node/2705731
* @param string $title
* Title of the debug message.
*
* @return void
* Return void.
*
* @throws \Exception
*/
function devel_debug_log_ddl(mixed $message, string $title = ''): void {
function ddl(mixed $message, string $title = ''): void {
$serialized = FALSE;
$message = devel_debug_log_ob_kint($message);
// @todo Find a way to store the initial message, instead of storing the entire
// TODO Find a way to store the initial message, instead of storing the entire
// debug markup returned by kint().
$connection = \Drupal::database();
$query = $connection->insert('devel_debug_log')
->fields([
->fields(array(
'timestamp' => \Drupal::time()->getRequestTime(),
'title' => $title,
'message' => $message,
'serialized' => $serialized ? 1 : 0,
]);
));
$query->execute();
}
/**
* Checks if the message has already been saved during the current page request.
* Checks if the message has already been saved during the current page request,
* and saves the message only if it is not a repetition of a previous one.
*
* @param mixed $message
* A debug message to save, which can be:
* - string: saved as is.
* - object or array: saved serialized.
* @param string $title
* Title for the debug message.
* Title for the debug message.
*
* @return void
* Returns void.
*
* @throws \Exception
*/
function devel_debug_log_once(mixed $message, string $title = ''): void {
function ddl_once(mixed $message, string $title = ''): void {
$message_history = &drupal_static(__FUNCTION__);
if (!is_resource($message)) {
......@@ -74,7 +72,7 @@ function devel_debug_log_once(mixed $message, string $title = ''): void {
$message_history[] = $hash;
}
devel_debug_log_ddl($message, $title);
ddl($message, $title);
}
/**
......@@ -87,21 +85,21 @@ function devel_debug_log_theme(array &$cache, $type, $theme, $path): array {
'content' => NULL,
'delete_form' => NULL,
],
],
]
];
}
/**
* Provides debug output for later printing.
*
* Kint() outputs the debug information at the top of the page. This function
* kint() outputs the debug information at the top of the page. This function
* allows you to get the output and use it for later printing.
*
* @param mixed $message
* The data that's displayed for debugging.
* The data that's displayed for debugging.
*
* @return string
* The debug information.
* The debug information.
*/
function devel_debug_log_ob_kint(mixed $message): string {
ob_start();
......@@ -109,8 +107,7 @@ function devel_debug_log_ob_kint(mixed $message): string {
Kint::$enabled_mode = Kint::MODE_RICH;
RichRenderer::$folder = FALSE;
Kint::dump($message);
}
else {
} else {
\Drupal::service('devel.dumper')->dump($message);
}
$output = ob_get_contents();
......
......@@ -6,16 +6,13 @@ use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Database\Connection;
use Drupal\Core\Datetime\DateFormatter;
use Drupal\Core\Form\FormBuilderInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* The main controller for the module.
*/
class DevelDebugLogController extends ControllerBase {
/**
* The Database Connection.
* The Database Connection
*
* @var \Drupal\Core\Database\Connection
*/
......@@ -24,7 +21,7 @@ class DevelDebugLogController extends ControllerBase {
/**
* The Serializer service.
*
* @var Symfony\Component\Serializer\Serializer
* @var Symfony\Component\Serializer\Serializer;
*/
protected $serializer;
......@@ -38,7 +35,7 @@ class DevelDebugLogController extends ControllerBase {
/**
* The FormBuilder object.
*
* @var Drupal\Core\Form\FormBuilderInterface
* @var Drupal\Core\Form\FormBuilderInterface;
*/
protected $formBuilder;
......@@ -57,14 +54,10 @@ class DevelDebugLogController extends ControllerBase {
/**
* DevelDebugLogController constructor.
*
* @param \Drupal\Core\Database\Connection $database
* The database object.
* @param \Drupal\Core\Datetime\DateFormatter $dateFormatter
* The dateFormatter object.
* @param \Symfony\Component\Serializer\Serializer $serializer
* The serializer object.
* @param \Drupal\Core\Form\FormBuilderInterface $formBuilder
* The formBuilder object.
* @param Connection $database
* @param DateFormatter $dateFormatter
* @param Serializer $serializer
* @param FormBuilderInterface $formBuilder
*/
public function __construct(Connection $database, DateFormatter $dateFormatter, Serializer $serializer, FormBuilderInterface $formBuilder) {
$this->database = $database;
......@@ -77,7 +70,7 @@ class DevelDebugLogController extends ControllerBase {
* Lists debug information.
*
* @return array
* Renderable array that contains a list of debug data.
* Renderable array that contains a list of debug data.
*/
public function listLogs() {
$query = $this->database->select('devel_debug_log', 'm')
......@@ -88,32 +81,31 @@ class DevelDebugLogController extends ControllerBase {
$rows = [];
foreach ($results as $result) {
$rows[] = [
$rows[] = array(
'title' => $result->title,
'time' => $this->dateFormatter
->format($result->timestamp, 'short'),
->format($result->timestamp, 'short'),
'message' => $result->message,
];
);
}
if (empty($rows)) {
return [
return array(
'#markup' => $this->t('No debug messages.'),
];
);
}
$build = [
'messages' => [
$build = array(
'messages' => array(
'#theme' => 'devel_debug_log_list',
'#content' => $rows,
'#delete_form' => $this->formBuilder->getForm('Drupal\devel_debug_log\Form\DevelDebugLogDeleteForm'),
],
'pager' => [
'#type' => 'pager',
],
];
),
'pager' => array(
'#type' => 'pager'
),
);
return $build;
}
}
......@@ -8,14 +8,9 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* The delete form.
*/
class DevelDebugLogDeleteForm extends FormBase {
/**
* The messenger interface.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
......@@ -39,39 +34,39 @@ class DevelDebugLogDeleteForm extends FormBase {
$this->messenger = $messenger;
}
/**
* {@inheritdoc}
* @inheritdoc
*/
public function getFormId() {
return 'ddl_delete_form';
}
/**
* {@inheritdoc}
* @inheritdoc
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['ddl_clear'] = [
$form['ddl_clear'] = array(
'#type' => 'fieldset',
'#title' => $this->t('Clear debug log messages'),
'#description' => $this->t('This will permanently remove the log messages from the database.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
];
$form['ddl_clear']['clear'] = [
);
$form['ddl_clear']['clear'] = array(
'#type' => 'submit',
'#value' => $this->t('Clear log messages'),
];
);
return $form;
}
/**
* {@inheritdoc}
* @inheritdoc
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
Database::getConnection()->delete('devel_debug_log')
->execute();
$this->messenger->addMessage($this->t('All debug messages have been cleared.'));
}
}
......@@ -24,12 +24,12 @@ class DevelDebugLogExtension extends AbstractExtension {
* {@inheritdoc}
*/
public function getFunctions() {
return [
new TwigFunction('ddl', [$this, 'ddl'], [
return array(
new TwigFunction('ddl', array($this, 'ddl'), array(
'needs_environment' => TRUE,
'needs_context' => TRUE,
]),
];
)),
);
}
/**
......@@ -41,14 +41,14 @@ class DevelDebugLogExtension extends AbstractExtension {
* An array of parameters passed to the template.
*/
public function ddl(\Twig_Environment $env, array $context) {
// Don't do anything unless twig_debug is enabled. This reads from the Twig.
// Don't do anything unless twig_debug is enabled. This reads from the Twig
if (!$env->isDebug()) {
return;
}
if (func_num_args() === 2) {
// No arguments passed, display full Twig context.
$ddl_variables = [];
$ddl_variables = array();
foreach ($context as $key => $value) {
if (!$value instanceof \Twig_Template) {
$ddl_variables[$key] = $value;
......
......@@ -5,4 +5,4 @@
{% endif %}
{{ value.time }}
{{ value.message|raw }}
{% endfor %}
{% endfor %}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment