class DbLogFilters

Same name and namespace in other branches
  1. main core/modules/dblog/src/DbLogFilters.php \Drupal\dblog\DbLogFilters

Filter methods for the dblog module.

Hierarchy

  • class \Drupal\dblog\DbLogFilters uses \Drupal\Core\StringTranslation\StringTranslationTrait

Expanded class hierarchy of DbLogFilters

4 files declare their use of DbLogFilters
dblog.module in core/modules/dblog/dblog.module
DbLogController.php in core/modules/dblog/src/Controller/DbLogController.php
DblogFilterForm.php in core/modules/dblog/src/Form/DblogFilterForm.php
DblogTypes.php in core/modules/dblog/src/Plugin/views/filter/DblogTypes.php

File

core/modules/dblog/src/DbLogFilters.php, line 12

Namespace

Drupal\dblog
View source
class DbLogFilters {
  use StringTranslationTrait;
  public function __construct(protected readonly Connection $connection) {
  }
  
  /**
   * Gathers a list of uniquely defined database log message types.
   *
   * @return array
   *   List of uniquely defined database log message types.
   */
  public function getMessageTypes() : array {
    return $this->connection
      ->query('SELECT DISTINCT([type]) FROM {watchdog} ORDER BY [type]')
      ->fetchAllKeyed(0, 0);
  }
  
  /**
   * Creates a list of database log administration filters that can be applied.
   *
   * @return array
   *   Associative array of filters. The top-level keys are used as the form
   *   element names for the filters, and the values are arrays with the
   *   following elements:
   *   - title: Title of the filter.
   *   - where: The filter condition.
   *   - options: Array of options for the select list for the filter.
   */
  public function filters() : array {
    $filters = [];
    foreach ($this->getMessageTypes() as $type) {
      // phpcs:ignore Drupal.Semantics.FunctionT.NotLiteralString
      $types[$type] = $this->t($type);
    }
    if (!empty($types)) {
      $filters['type'] = [
        'title' => $this->t('Type'),
        'field' => 'w.type',
        'options' => $types,
      ];
    }
    $filters['severity'] = [
      'title' => $this->t('Severity'),
      'field' => 'w.severity',
      'options' => RfcLogLevel::getLevels(),
    ];
    return $filters;
  }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
DbLogFilters::filters public function Creates a list of database log administration filters that can be applied.
DbLogFilters::getMessageTypes public function Gathers a list of uniquely defined database log message types.
DbLogFilters::__construct public function
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language. 1

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.