You are here

public function ServerListBuilder::render in OAuth2 Server 8

Same name and namespace in other branches
  1. 2.0.x src/ServerListBuilder.php \Drupal\oauth2_server\ServerListBuilder::render()

Builds the entity listing as renderable array for table.html.twig.

@todo Add a link to add a new item to the #empty text.

Overrides EntityListBuilder::render

File

src/ServerListBuilder.php, line 90

Class

ServerListBuilder
Builds a listing of oauth2 server entities.

Namespace

Drupal\oauth2_server

Code

public function render() {
  $build = [];
  $build['table'] = [
    '#type' => 'table',
    '#header' => $this
      ->buildHeader(),
    '#title' => $this
      ->getTitle(),
    '#rows' => [],
    '#cache' => [
      'contexts' => $this->entityType
        ->getListCacheContexts(),
    ],
    '#attributes' => [
      'id' => 'oauth2-server-entity-list',
    ],
  ];
  $build['table']['#empty'] = $this
    ->t('No servers available. <a href="@link">Add server</a>.', [
    '@link' => Url::fromRoute('entity.oauth2_server.add_form')
      ->toString(),
  ]);

  /** @var \Drupal\oauth2_server\ServerInterface[] $servers */
  $servers = $this->storage
    ->loadMultiple();
  $this
    ->sortByStatusThenAlphabetically($servers);
  foreach ($servers as $entity) {
    if ($row = $this
      ->buildRow($entity)) {
      $build['table']['#rows'][$entity
        ->id()] = $row;
    }
  }
  $build['pager'] = [
    '#type' => 'pager',
  ];
  return $build;
}