Displays a listing of database log messages.
Messages are truncated at 56 chars. Full-length messages can be viewed on the message details page.
array A render array as expected by drupal_render().
public function overview() {
$filter = $this
->buildFilterQuery();
$rows = array();
$classes = static::getLogLevelClassMap();
$this->moduleHandler
->loadInclude('dblog', 'admin.inc');
$build['dblog_filter_form'] = drupal_get_form('dblog_filter_form');
$build['dblog_clear_log_form'] = drupal_get_form('dblog_clear_log_form');
$header = array(
// Icon column.
'',
array(
'data' => t('Type'),
'field' => 'w.type',
'class' => array(
RESPONSIVE_PRIORITY_MEDIUM,
),
),
array(
'data' => t('Date'),
'field' => 'w.wid',
'sort' => 'desc',
'class' => array(
RESPONSIVE_PRIORITY_LOW,
),
),
t('Message'),
array(
'data' => t('User'),
'field' => 'u.name',
'class' => array(
RESPONSIVE_PRIORITY_MEDIUM,
),
),
array(
'data' => t('Operations'),
'class' => array(
RESPONSIVE_PRIORITY_LOW,
),
),
);
$query = $this->database
->select('watchdog', 'w')
->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
->extend('Drupal\\Core\\Database\\Query\\TableSortExtender');
$query
->leftJoin('users', 'u', 'w.uid = u.uid');
$query
->fields('w', array(
'wid',
'uid',
'severity',
'type',
'timestamp',
'message',
'variables',
'link',
));
$query
->addField('u', 'name');
if (!empty($filter['where'])) {
$query
->where($filter['where'], $filter['args']);
}
$result = $query
->limit(50)
->orderByHeader($header)
->execute();
foreach ($result as $dblog) {
// Check for required properties.
if (isset($dblog->message) && isset($dblog->variables)) {
// Messages without variables or user specified text.
if ($dblog->variables === 'N;') {
$message = $dblog->message;
}
else {
$message = t($dblog->message, unserialize($dblog->variables));
}
if (isset($dblog->wid)) {
// Truncate link_text to 56 chars of message.
$log_text = Unicode::truncate(filter_xss($message, array()), 56, TRUE, TRUE);
$message = l($log_text, 'admin/reports/event/' . $dblog->wid, array(
'html' => TRUE,
));
}
}
$rows[] = array(
'data' => array(
// Cells.
array(
'class' => array(
'icon',
),
),
t($dblog->type),
format_date($dblog->timestamp, 'short'),
$message,
theme('username', array(
'account' => $dblog,
)),
filter_xss($dblog->link),
),
// Attributes for table row.
'class' => array(
drupal_html_class('dblog-' . $dblog->type),
$classes[$dblog->severity],
),
);
}
$build['dblog_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#attributes' => array(
'id' => 'admin-dblog',
'class' => array(
'admin-dblog',
),
),
'#empty' => t('No log messages available.'),
);
$build['dblog_pager'] = array(
'#theme' => 'pager',
);
return $build;
}