function DbtngExampleController::entryList

Same name in other branches
  1. 4.0.x modules/dbtng_example/src/Controller/DbtngExampleController.php \Drupal\dbtng_example\Controller\DbtngExampleController::entryList()

Render a list of entries in the database.

1 string reference to 'DbtngExampleController::entryList'
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 45

Class

DbtngExampleController
Controller for DBTNG Example.

Namespace

Drupal\dbtng_example\Controller

Code

public function entryList() {
    $content = [];
    $content['message'] = [
        '#markup' => $this->t('Generate a list of all entries in the database. There is no filter in the query.'),
    ];
    $rows = [];
    $headers = [
        $this->t('Id'),
        $this->t('uid'),
        $this->t('Name'),
        $this->t('Surname'),
        $this->t('Age'),
    ];
    $entries = $this->repository
        ->load();
    foreach ($entries as $entry) {
        // Sanitize each entry.
        $rows[] = array_map('Drupal\\Component\\Utility\\Html::escape', (array) $entry);
    }
    $content['table'] = [
        '#type' => 'table',
        '#header' => $headers,
        '#rows' => $rows,
        '#empty' => $this->t('No entries available.'),
    ];
    // Don't cache this page.
    $content['#cache']['max-age'] = 0;
    return $content;
}