You are here

public function ContentLogController::overview in Content Synchronization 8

Same name and namespace in other branches
  1. 8.2 src/Controller/ContentLogController.php \Drupal\content_sync\Controller\ContentLogController::overview()
  2. 3.0.x src/Controller/ContentLogController.php \Drupal\content_sync\Controller\ContentLogController::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

Drupal\content_sync\Form\logClearLogConfirmForm

Drupal\content_sync\Controller\LogController::eventDetails()

1 string reference to 'ContentLogController::overview'
content_sync.routing.yml in ./content_sync.routing.yml
content_sync.routing.yml

File

src/Controller/ContentLogController.php, line 121

Class

ContentLogController
Returns responses for content_sync routes.

Namespace

Drupal\content_sync\Controller

Code

public function overview() {
  $filter = $this
    ->buildFilterQuery();
  $rows = [];
  $classes = static::getLogLevelClassMap();
  $this->moduleHandler
    ->loadInclude('module_sync', 'admin.inc');

  //$build['admin_filter_form'] = $this->formBuilder->getForm('Drupal\content_sync\Form\ContentLogFilterForm');
  $header = [
    // Icon column.
    '',
    /*  [
        'data' => $this->t('Type'),
        'field' => 'w.type',
        'class' => [RESPONSIVE_PRIORITY_MEDIUM]], */
    [
      'data' => $this
        ->t('Date'),
      'field' => 'w.csid',
      'sort' => 'desc',
      'class' => [
        RESPONSIVE_PRIORITY_LOW,
      ],
    ],
    $this
      ->t('Message'),
    [
      'data' => $this
        ->t('User'),
      'field' => 'ufd.name',
      'class' => [
        RESPONSIVE_PRIORITY_MEDIUM,
      ],
    ],
    [
      'data' => $this
        ->t('Operations'),
      'class' => [
        RESPONSIVE_PRIORITY_LOW,
      ],
    ],
  ];
  $query = $this->database
    ->select('cs_logs', 'w')
    ->extend('\\Drupal\\Core\\Database\\Query\\PagerSelectExtender')
    ->extend('\\Drupal\\Core\\Database\\Query\\TableSortExtender');
  $query
    ->fields('w', [
    'csid',
    '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 $log) {
    $message = $this
      ->formatMessage($log);
    if ($message && isset($log->csid)) {
      $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('log.event', ['event_id' => $log->csid], [
          'attributes' => [
            // 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 = [
      '#theme' => 'username',
      '#account' => $this->userStorage
        ->load($log->uid),
    ];
    $rows[] = [
      'data' => [
        // Cells.
        [
          'class' => [
            'icon',
          ],
        ],
        // $this->t($log->type),
        $this->dateFormatter
          ->format($log->timestamp, 'short'),
        $message,
        [
          'data' => $username,
        ],
        [
          'data' => [
            '#markup' => $log->link,
          ],
        ],
      ],
      // Attributes for table row.
      'class' => [
        Html::getClass('cslog-' . $log->type),
        $classes[$log->severity],
      ],
    ];
  }
  $build['log_table'] = [
    '#type' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#attributes' => [
      'id' => 'admin-cslog',
      'class' => [
        'admin-cslog',
      ],
    ],
    '#empty' => $this
      ->t('No log messages available.'),
    '#attached' => [
      'library' => [
        'cslog/drupal.cslog',
      ],
    ],
  ];
  $build['log_pager'] = [
    '#type' => 'pager',
  ];
  return $build;
}