first commit

This commit is contained in:
2024-07-15 12:33:27 +02:00
commit ce50ae282b
22084 changed files with 2623791 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
<?php
namespace Drupal\dblog\Plugin\rest\resource;
use Drupal\Core\Database\Database;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\rest\Attribute\RestResource;
use Drupal\rest\Plugin\ResourceBase;
use Drupal\rest\ResourceResponse;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Provides a resource for database watchdog log entries.
*/
#[RestResource(
id: "dblog",
label: new TranslatableMarkup("Watchdog database log"),
uri_paths: [
"canonical" => "/dblog/{id}",
]
)]
class DbLogResource extends ResourceBase {
/**
* Responds to GET requests.
*
* Returns a watchdog log entry for the specified ID.
*
* @param int $id
* The ID of the watchdog log entry.
*
* @return \Drupal\rest\ResourceResponse
* The response containing the log entry.
*
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
* Thrown when the log entry was not found.
* @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
* Thrown when no log entry was provided.
*/
public function get($id = NULL) {
if ($id) {
$record = Database::getConnection()->query("SELECT * FROM {watchdog} WHERE [wid] = :wid", [':wid' => $id])
->fetchAssoc();
if (!empty($record)) {
return new ResourceResponse($record);
}
throw new NotFoundHttpException("Log entry with ID '$id' was not found");
}
throw new BadRequestHttpException('No log entry ID was provided');
}
}

View File

@@ -0,0 +1,70 @@
<?php
namespace Drupal\dblog\Plugin\views\field;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Attribute\ViewsField;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
/**
* Provides a field handler that renders a log event with replaced variables.
*
* @ingroup views_field_handlers
*/
#[ViewsField("dblog_message")]
class DblogMessage extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) {
parent::init($view, $display, $options);
if ($this->options['replace_variables']) {
$this->additional_fields['variables'] = 'variables';
}
}
/**
* {@inheritdoc}
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['replace_variables'] = ['default' => TRUE];
return $options;
}
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['replace_variables'] = [
'#title' => $this->t('Replace variables'),
'#type' => 'checkbox',
'#default_value' => $this->options['replace_variables'],
];
}
/**
* {@inheritdoc}
*/
public function render(ResultRow $values) {
$value = $this->getValue($values);
if ($this->options['replace_variables']) {
$variables = unserialize($this->getvalue($values, 'variables'));
return new FormattableMarkup($value, (array) $variables);
}
else {
return $this->sanitizeValue($value);
}
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Drupal\dblog\Plugin\views\field;
use Drupal\views\Attribute\ViewsField;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
/**
* Provides a field handler that renders operation link markup.
*
* @ingroup views_field_handlers
*/
#[ViewsField("dblog_operations")]
class DblogOperations extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function clickSortable() {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function render(ResultRow $values) {
$value = $this->getValue($values);
return $this->sanitizeValue($value, 'xss_admin');
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace Drupal\dblog\Plugin\views\filter;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Attribute\ViewsFilter;
use Drupal\views\Plugin\views\filter\InOperator;
/**
* Exposes log types to views module.
*/
#[ViewsFilter("dblog_types")]
class DblogTypes extends InOperator {
/**
* {@inheritdoc}
*/
public function getValueOptions() {
if (!isset($this->valueOptions)) {
$this->valueOptions = _dblog_get_message_types();
}
return $this->valueOptions;
}
/**
* {@inheritdoc}
*/
protected function valueForm(&$form, FormStateInterface $form_state) {
parent::valueForm($form, $form_state);
$form['value']['#access'] = !empty($form['value']['#options']);
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace Drupal\dblog\Plugin\views\wizard;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsWizard;
use Drupal\views\Plugin\views\wizard\WizardPluginBase;
/**
* Defines a wizard for the watchdog table.
*/
#[ViewsWizard(
id: 'watchdog',
title: new TranslatableMarkup('Log entries'),
base_table: 'watchdog'
)]
class Watchdog extends WizardPluginBase {
/**
* Set the created column.
*
* @var string
*/
protected $createdColumn = 'timestamp';
/**
* {@inheritdoc}
*/
protected function defaultDisplayOptions() {
$display_options = parent::defaultDisplayOptions();
// Add permission-based access control.
$display_options['access']['type'] = 'perm';
$display_options['access']['options']['perm'] = 'access site reports';
return $display_options;
}
}