You are here

public function DbtngExampleController::entryAdvancedList in Examples for Developers 3.x

Same name and namespace in other branches
  1. 8 dbtng_example/src/Controller/DbtngExampleController.php \Drupal\dbtng_example\Controller\DbtngExampleController::entryAdvancedList()

Render a filtered list of entries in the database.

1 string reference to 'DbtngExampleController::entryAdvancedList'
dbtng_example.routing.yml in modules/dbtng_example/dbtng_example.routing.yml
modules/dbtng_example/dbtng_example.routing.yml

File

modules/dbtng_example/src/Controller/DbtngExampleController.php, line 82

Class

DbtngExampleController
Controller for DBTNG Example.

Namespace

Drupal\dbtng_example\Controller

Code

public function entryAdvancedList() {
  $content = [];
  $content['message'] = [
    '#markup' => $this
      ->t('A more complex list of entries in the database. Only the entries with name = "John" and age older than 18 years are shown, the username of the person who created the entry is also shown.'),
  ];
  $headers = [
    $this
      ->t('Id'),
    $this
      ->t('Created by'),
    $this
      ->t('Name'),
    $this
      ->t('Surname'),
    $this
      ->t('Age'),
  ];
  $rows = [];
  $entries = $this->repository
    ->advancedLoad();
  foreach ($entries as $entry) {

    // Sanitize each entry.
    $rows[] = array_map('Drupal\\Component\\Utility\\Html::escape', $entry);
  }
  $content['table'] = [
    '#type' => 'table',
    '#header' => $headers,
    '#rows' => $rows,
    '#attributes' => [
      'id' => 'dbtng-example-advanced-list',
    ],
    '#empty' => $this
      ->t('No entries available.'),
  ];

  // Don't cache this page.
  $content['#cache']['max-age'] = 0;
  return $content;
}