You are here

public function Oauth2TokenListBuilder::buildRow in Simple OAuth (OAuth2) & OpenID Connect 8.4

Same name and namespace in other branches
  1. 8.2 src/Oauth2TokenListBuilder.php \Drupal\simple_oauth\Oauth2TokenListBuilder::buildRow()
  2. 8.3 src/Oauth2TokenListBuilder.php \Drupal\simple_oauth\Oauth2TokenListBuilder::buildRow()
  3. 5.x src/Oauth2TokenListBuilder.php \Drupal\simple_oauth\Oauth2TokenListBuilder::buildRow()

Builds a row for an entity in the entity listing.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for this row of the list.

Return value

array A render array structure of fields for this entity.

Overrides EntityListBuilder::buildRow

See also

\Drupal\Core\Entity\EntityListBuilder::render()

File

src/Oauth2TokenListBuilder.php, line 32

Class

Oauth2TokenListBuilder
Defines a class to build a listing of Access Token entities.

Namespace

Drupal\simple_oauth

Code

public function buildRow(EntityInterface $entity) {

  /* @var $entity \Drupal\simple_oauth\Entity\Oauth2Token */
  $row['id'] = $entity
    ->id();
  $row['type'] = $entity
    ->bundle();
  $row['user'] = NULL;
  $row['name'] = $entity
    ->toLink(sprintf('%s…', substr($entity
    ->label(), 0, 10)));
  $row['client'] = NULL;
  $row['scopes'] = NULL;
  if (($user = $entity
    ->get('auth_user_id')) && $user->entity) {
    $row['user'] = $user->entity
      ->toLink($user->entity
      ->label());
  }
  if (($client = $entity
    ->get('client')) && $client->entity) {
    $row['client'] = $client->entity
      ->toLink($client->entity
      ->label(), 'edit-form');
  }

  /** @var \Drupal\Core\Field\EntityReferenceFieldItemListInterface $scopes */
  if ($scopes = $entity
    ->get('scopes')) {
    $row['scopes'] = implode(', ', array_map(function (RoleInterface $role) {
      return $role
        ->label();
    }, $scopes
      ->referencedEntities()));
  }
  return $row + parent::buildRow($entity);
}