You are here

public function ContentLogController::eventDetails in Content Synchronization 8

Same name and namespace in other branches
  1. 8.2 src/Controller/ContentLogController.php \Drupal\content_sync\Controller\ContentLogController::eventDetails()
  2. 3.0.x src/Controller/ContentLogController.php \Drupal\content_sync\Controller\ContentLogController::eventDetails()

Displays details about a specific database log message.

Parameters

int $event_id: Unique ID of the database log message.

Return value

array If the ID is located in the Database Logging table, a build array in the format expected by drupal_render();

File

src/Controller/ContentLogController.php, line 238

Class

ContentLogController
Returns responses for content_sync routes.

Namespace

Drupal\content_sync\Controller

Code

public function eventDetails($event_id) {
  $build = [];
  if ($cslog = $this->database
    ->query('SELECT w.*, u.uid FROM {cs_logs} w LEFT JOIN {users} u ON u.uid = w.uid WHERE w.csid = :id', [
    ':id' => $event_id,
  ])
    ->fetchObject()) {
    $severity = RfcLogLevel::getLevels();
    $message = $this
      ->formatMessage($cslog);
    $username = [
      '#theme' => 'username',
      '#account' => $cslog->uid ? $this->userStorage
        ->load($cslog->uid) : User::getAnonymousUser(),
    ];
    $rows = [
      [
        [
          'data' => $this
            ->t('Type'),
          'header' => TRUE,
        ],
        $this
          ->t($cslog->type),
      ],
      [
        [
          'data' => $this
            ->t('Date'),
          'header' => TRUE,
        ],
        $this->dateFormatter
          ->format($cslog->timestamp, 'long'),
      ],
      [
        [
          'data' => $this
            ->t('User'),
          'header' => TRUE,
        ],
        [
          'data' => $username,
        ],
      ],
      [
        [
          'data' => $this
            ->t('Location'),
          'header' => TRUE,
        ],
        $this
          ->l($cslog->location, $cslog->location ? Url::fromUri($cslog->location) : Url::fromRoute('<none>')),
      ],
      [
        [
          'data' => $this
            ->t('Referrer'),
          'header' => TRUE,
        ],
        $this
          ->l($cslog->referer, $cslog->referer ? Url::fromUri($cslog->referer) : Url::fromRoute('<none>')),
      ],
      [
        [
          'data' => $this
            ->t('Message'),
          'header' => TRUE,
        ],
        $message,
      ],
      [
        [
          'data' => $this
            ->t('Severity'),
          'header' => TRUE,
        ],
        $severity[$cslog->severity],
      ],
      [
        [
          'data' => $this
            ->t('Hostname'),
          'header' => TRUE,
        ],
        $cslog->hostname,
      ],
      [
        [
          'data' => $this
            ->t('Operations'),
          'header' => TRUE,
        ],
        [
          'data' => [
            '#markup' => $cslog->link,
          ],
        ],
      ],
    ];
    $build['cslog_table'] = [
      '#type' => 'table',
      '#rows' => $rows,
      '#attributes' => [
        'class' => [
          'cslog-event',
        ],
      ],
      '#attached' => [
        'library' => [
          'cslog/drupal.cslog',
        ],
      ],
    ];
  }
  return $build;
}