You are here

public function ClientListBuilder::render in OAuth2 Server 8

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

Parameters

\Drupal\oauth2_server\ServerInterface $oauth2_server: The server of which the clients should be limited to.

Return value

array The client list as a renderable array.

Overrides EntityListBuilder::render

File

src/ClientListBuilder.php, line 81

Class

ClientListBuilder
Builds a listing of oauth2 server client entities.

Namespace

Drupal\oauth2_server

Code

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

    /** @var \Drupal\oauth2_server\ClientInterface[] $client */
    $clients = $this->storage
      ->loadByProperties([
      'server_id' => $oauth2_server
        ->id(),
    ]);
  }
  else {

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