You are here

protected function AccessTokenListBuilder::getDefaultOperations in Access unpublished 8

Gets this list's default operations.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity the operations are for.

Return value

array The array structure is identical to the return value of self::getOperations().

Overrides EntityListBuilder::getDefaultOperations

1 call to AccessTokenListBuilder::getDefaultOperations()
EntityFormAccessTokenListBuilder::getDefaultOperations in src/EntityFormAccessTokenListBuilder.php
Gets this list's default operations.
1 method overrides AccessTokenListBuilder::getDefaultOperations()
EntityFormAccessTokenListBuilder::getDefaultOperations in src/EntityFormAccessTokenListBuilder.php
Gets this list's default operations.

File

src/AccessTokenListBuilder.php, line 127

Class

AccessTokenListBuilder
Defines a class to build a listing of access token entities.

Namespace

Drupal\access_unpublished

Code

protected function getDefaultOperations(EntityInterface $token) {

  /** @var \Drupal\access_unpublished\AccessTokenInterface $token */
  $operations = parent::getDefaultOperations($token);
  if ($token
    ->access('delete') && $token
    ->hasLinkTemplate('delete')) {
    $operations['delete'] = [
      'title' => $this
        ->t('Delete'),
      'weight' => 100,
      'url' => $this
        ->ensureDestination($token
        ->toUrl('delete', [
        'query' => [
          'handler' => $this->handlerName,
        ],
      ])),
      'attributes' => [
        'class' => [
          'use-ajax',
        ],
      ],
    ];
  }
  if ($token
    ->access('renew') && $token
    ->isExpired()) {
    $operations['renew'] = [
      'title' => $this
        ->t('Renew'),
      'url' => $this
        ->ensureDestination($token
        ->toUrl('renew', [
        'query' => [
          'handler' => $this->handlerName,
        ],
      ])),
      'weight' => 50,
      'attributes' => [
        'class' => [
          'use-ajax',
        ],
      ],
    ];
  }
  else {
    $url = $this->accessTokenManager
      ->getAccessTokenUrl($token, $token
      ->getHost()
      ->language());
    $operations['copy'] = [
      'title' => $this
        ->t('Copy'),
      'url' => Url::fromUserInput('#'),
      'attributes' => [
        'data-unpublished-access-url' => $url,
        'class' => [
          'clipboard-button',
        ],
      ],
      'weight' => 50,
    ];
  }
  return $operations;
}