You are here

public function AccessTokenManager::getAccessTokenUrl in Access unpublished 8

Generates a URL containing the access token hash value.

Parameters

\Drupal\access_unpublished\AccessTokenInterface $token: The access token.

\Drupal\Core\Language\LanguageInterface $language: The language of the generated URL.

Return value

\Drupal\Core\GeneratedUrl The generated URL that includes the hash parameter.

Throws

\Drupal\Core\Entity\EntityMalformedException

File

src/AccessTokenManager.php, line 161

Class

AccessTokenManager
Service to work with access tokens.

Namespace

Drupal\access_unpublished

Code

public function getAccessTokenUrl(AccessTokenInterface $token, LanguageInterface $language) {
  $tokenKey = $this->configFactory
    ->get('access_unpublished.settings')
    ->get('hash_key');
  $rel = 'canonical';

  // Link to a forward revision if available.
  if ($this->moderationInfo && $this->moderationInfo
    ->hasPendingRevision($token
    ->getHost()) && $token
    ->getHost()
    ->getEntityType()
    ->hasLinkTemplate('latest-version')) {
    $rel = 'latest-version';
  }
  return $token
    ->getHost()
    ->toUrl($rel, [
    'query' => [
      $tokenKey => $token
        ->get('value')->value,
    ],
    'absolute' => TRUE,
    'language' => $language,
  ])
    ->toString();
}