You are here

public function ThunderRedirect::resolve in Thunder 6.2.x

Resolver.

Parameters

string $path: The url path.

\Drupal\Core\Cache\RefinableCacheableDependencyInterface $metadata: The metadata.

Return value

array The redirect data.

File

modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderRedirect.php, line 102

Class

ThunderRedirect
Gets the ID of current user.

Namespace

Drupal\thunder_gqls\Plugin\GraphQL\DataProducer

Code

public function resolve(string $path, RefinableCacheableDependencyInterface $metadata) {
  if (!$this->redirectRepository) {
    return [];
  }
  $language = $this->languageManager
    ->getCurrentLanguage()
    ->getId();

  /** @var \Drupal\redirect\Entity\Redirect|null $redirect */
  $redirect = $this->redirectRepository
    ->findMatchingRedirect($path, [], $language);
  if ($redirect instanceof Redirect) {
    $urlObject = $redirect
      ->getRedirectUrl();
    $metadata
      ->addCacheTags(array_merge($redirect
      ->getCacheTags(), [
      'redirect_list',
    ]));
    return [
      'url' => $urlObject
        ->toString(TRUE)
        ->getGeneratedUrl(),
      'status' => $redirect
        ->getStatusCode(),
    ];
  }
  return [];
}