You are here

public function ObjectLogController::listing in Object Log 8

Prepares a table listing of stored objects. .

Return value

array A Drupal render array.

1 call to ObjectLogController::listing()
ObjectLogController::objectDetails in src/Controller/ObjectLogController.php
Display a stored object.
1 string reference to 'ObjectLogController::listing'
object_log.routing.yml in ./object_log.routing.yml
object_log.routing.yml

File

src/Controller/ObjectLogController.php, line 78
Contains \Drupal\object_log\Controller\ObjectLogController.

Class

ObjectLogController
Contains callbacks for Object Log routes.

Namespace

Drupal\object_log\Controller

Code

public function listing() {
  $rows = array();
  $header = array(
    array(
      'data' => $this
        ->t('Label'),
      'field' => 'ol.label',
    ),
    array(
      'data' => $this
        ->t('Date'),
      'field' => 'ol.created',
      'sort' => 'desc',
    ),
  );
  $query = $this->database
    ->select('object_log', 'ol')
    ->extend('\\Drupal\\Core\\Database\\Query\\PagerSelectExtender')
    ->extend('\\Drupal\\Core\\Database\\Query\\TableSortExtender');
  $query
    ->fields('ol', array(
    'label',
    'created',
  ));
  $result = $query
    ->limit(25)
    ->orderByHeader($header)
    ->execute();
  foreach ($result as $item) {
    $rows[] = array(
      Link::fromTextAndUrl($item->label, Url::fromRoute('object_log.object', array(
        'label' => $item->label,
      ))),
      $this->dateFormatter
        ->format($item->created, 'short'),
    );
  }
  $build = array(
    'object_log' => array(
      '#theme' => 'table',
      '#header' => $header,
      '#rows' => $rows,
      '#attributes' => array(
        'id' => 'object_log',
      ),
      '#empty' => t('No variables stored.'),
    ),
    'object_log_pager' => array(
      '#type' => 'pager',
    ),
    'clear_form' => $this->formBuilder
      ->getForm('\\Drupal\\object_log\\Form\\ObjectLogClearLogForm'),
  );
  return $build;
}