function DbLogController::topLogMessages

Same name in other branches
  1. 9 core/modules/dblog/src/Controller/DbLogController.php \Drupal\dblog\Controller\DbLogController::topLogMessages()
  2. 8.9.x core/modules/dblog/src/Controller/DbLogController.php \Drupal\dblog\Controller\DbLogController::topLogMessages()
  3. 11.x core/modules/dblog/src/Controller/DbLogController.php \Drupal\dblog\Controller\DbLogController::topLogMessages()

Shows the most frequent log messages of a given event type.

Messages are not truncated on this page because events detailed herein do not have links to a detailed view.

Parameters

string $type: Type of database log events to display (e.g., 'search').

Return value

array A build array in the format expected by \Drupal\Core\Render\RendererInterface::render().

1 string reference to 'DbLogController::topLogMessages'
dblog.routing.yml in core/modules/dblog/dblog.routing.yml
core/modules/dblog/dblog.routing.yml

File

core/modules/dblog/src/Controller/DbLogController.php, line 416

Class

DbLogController
Returns responses for dblog routes.

Namespace

Drupal\dblog\Controller

Code

public function topLogMessages($type) {
    $header = [
        [
            'data' => $this->t('Count'),
            'field' => 'count',
            'sort' => 'desc',
        ],
        [
            'data' => $this->t('Message'),
            'field' => 'message',
        ],
    ];
    $count_query = $this->database
        ->select('watchdog');
    $count_query->addExpression('COUNT(DISTINCT([message]))');
    $count_query->condition('type', $type);
    $query = $this->database
        ->select('watchdog', 'w')
        ->extend(PagerSelectExtender::class)
        ->extend(TableSortExtender::class);
    $query->addExpression('COUNT([wid])', 'count');
    $query = $query->fields('w', [
        'message',
        'variables',
    ])
        ->condition('w.type', $type)
        ->groupBy('message')
        ->groupBy('variables')
        ->limit(30)
        ->orderByHeader($header);
    $query->setCountQuery($count_query);
    $result = $query->execute();
    $rows = [];
    foreach ($result as $dblog) {
        if ($message = $this->formatMessage($dblog)) {
            $rows[] = [
                $dblog->count,
                $message,
            ];
        }
    }
    $build['dblog_top_table'] = [
        '#type' => 'table',
        '#header' => $header,
        '#rows' => $rows,
        '#empty' => $this->t('No log messages available.'),
        '#attached' => [
            'library' => [
                'dblog/drupal.dblog',
            ],
        ],
    ];
    $build['dblog_top_pager'] = [
        '#type' => 'pager',
    ];
    return $build;
}

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