You are here

public function ScopeListBuilder::render in OAuth2 Server 8

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

Parameters

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

Return value

array The scope list as a renderable array.

Overrides EntityListBuilder::render

File

src/ScopeListBuilder.php, line 80

Class

ScopeListBuilder
Builds a listing of oauth2 server 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-scope-entity-list',
    ],
  ];
  $build['table']['#empty'] = $this
    ->t('No scopes available. <a href="@link">Add scope</a>.', [
    '@link' => Url::fromRoute('entity.oauth2_server.scopes.add_form', [
      'oauth2_server' => $oauth2_server
        ->id(),
    ])
      ->toString(),
  ]);
  if ($oauth2_server) {

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

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