DbLogController::overview

public DbLogController::overview()

Displays a listing of database log messages.

Messages are truncated at 56 chars. Full-length messages can be viewed on the message details page.

Return value

array A render array as expected by drupal_render().

See also

dblog_clear_log_form()

dblog_event()

File

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

Class

DbLogController
Returns responses for dblog routes.

Namespace

Drupal\dblog\Controller

Code

public function overview() {

  $filter = $this->buildFilterQuery();
  $rows = array();

  $classes = static::getLogLevelClassMap();

  $this->moduleHandler->loadInclude('dblog', 'admin.inc');

  $build['dblog_filter_form'] = $this->formBuilder->getForm('Drupal\dblog\Form\DblogFilterForm');

  $header = array(
    // Icon column.
    '',
    array(
      'data' => $this->t('Type'),
      'field' => 'w.type',
      'class' => array(RESPONSIVE_PRIORITY_MEDIUM)),
    array(
      'data' => $this->t('Date'),
      'field' => 'w.wid',
      'sort' => 'desc',
      'class' => array(RESPONSIVE_PRIORITY_LOW)),
    $this->t('Message'),
    array(
      'data' => $this->t('User'),
      'field' => 'ufd.name',
      'class' => array(RESPONSIVE_PRIORITY_MEDIUM)),
    array(
      'data' => $this->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->fields('w', array(
    'wid',
    'uid',
    'severity',
    'type',
    'timestamp',
    'message',
    'variables',
    'link',
  ));
  $query->leftJoin('users_field_data', 'ufd', 'w.uid = ufd.uid');

  if (!empty($filter['where'])) {
    $query->where($filter['where'], $filter['args']);
  }
  $result = $query
  ->limit(50)
    ->orderByHeader($header)
    ->execute();

  foreach ($result as $dblog) {
    $message = $this->formatMessage($dblog);
    if ($message && isset($dblog->wid)) {
      $title = Unicode::truncate(Html::decodeEntities(strip_tags($message)), 256, TRUE, TRUE);
      $log_text = Unicode::truncate($title, 56, TRUE, TRUE);
      // The link generator will escape any unsafe HTML entities in the final
      // text.
      $message = $this->l($log_text, new Url('dblog.event', array('event_id' => $dblog->wid), array(
        'attributes' => array(
          // Provide a title for the link for useful hover hints. The
          // Attribute object will escape any unsafe HTML entities in the
          // final text.
          'title' => $title,
        ),
      )));
    }
    $username = array(
      '#theme' => 'username',
      '#account' => $this->userStorage->load($dblog->uid),
    );
    $rows[] = array(
      'data' => array(
        // Cells.
        array('class' => array('icon')),
        $this->t($dblog->type),
        $this->dateFormatter->format($dblog->timestamp, 'short'),
        $message,
        array('data' => $username),
        array('data' => array('#markup' => $dblog->link)),
      ),
      // Attributes for table row.
      'class' => array(Html::getClass('dblog-' . $dblog->type), $classes[$dblog->severity]),
    );
  }

  $build['dblog_table'] = array(
    '#type' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#attributes' => array('id' => 'admin-dblog', 'class' => array('admin-dblog')),
    '#empty' => $this->t('No log messages available.'),
    '#attached' => array(
      'library' => array('dblog/drupal.dblog'),
    ),
  );
  $build['dblog_pager'] = array('#type' => 'pager');

  return $build;

}
doc_Drupal
2016-10-29 09:01:16
Comments
Leave a Comment

Please login to continue.