public function DevelMailLoggerController::listMails in Devel Mail Logger 8
Show a list of mails from db.
1 string reference to 'DevelMailLoggerController::listMails'
File
- src/
Controller/ DevelMailLoggerController.php, line 74
Class
- DevelMailLoggerController
- Class DevelMailLoggerController.
Namespace
Drupal\devel_mail_logger\ControllerCode
public function listMails() {
$header = [
[
'data' => $this
->t('Date'),
'field' => 'm.timestamp',
'sort' => 'desc',
'class' => [
RESPONSIVE_PRIORITY_MEDIUM,
],
],
[
'data' => $this
->t('To'),
'field' => 'm.recipient',
'class' => [
RESPONSIVE_PRIORITY_MEDIUM,
],
],
[
'data' => $this
->t('Subject'),
'field' => 'm.subject',
'class' => [
RESPONSIVE_PRIORITY_LOW,
],
],
];
$query = $this->database
->select('devel_mail_logger', 'm')
->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
->extend('\\Drupal\\Core\\Database\\Query\\TableSortExtender');
$results = $query
->fields('m', [
'id',
'timestamp',
'subject',
'recipient',
])
->limit(50)
->orderByHeader($header)
->execute();
$rows = [];
foreach ($results as $result) {
$rows[] = [
'data' => [
$this
->t($this->dateFormatter
->format($result->timestamp, 'short')),
$result->recipient,
Link::createFromRoute($result->subject, 'devel_mail_logger.mail', [
'id' => $result->id,
]),
],
];
}
$build = [
'form' => $this->formBuilder
->getForm('Drupal\\devel_mail_logger\\Form\\DevelMailLoggerDeleteForm'),
'mail_table' => [
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#attributes' => [
'id' => 'admin-dblog',
'class' => [
'admin-dblog',
],
],
'#empty' => $this
->t('No debug mails available.'),
],
'pager' => [
'#type' => 'pager',
],
];
return $build;
}