From 9027b92f8c8bf21f13ff6acfd23f9fc13fdc4a05 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Fri, 13 Sep 2024 15:08:00 -0400 Subject: [PATCH] refactor: GQL responses need to include the path prefix, too --- src/gql/resolvers/RetourResolver.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/gql/resolvers/RetourResolver.php b/src/gql/resolvers/RetourResolver.php index 38cb2264..00e9ea97 100644 --- a/src/gql/resolvers/RetourResolver.php +++ b/src/gql/resolvers/RetourResolver.php @@ -15,8 +15,8 @@ use craft\base\Element; use craft\errors\SiteNotFoundException; use craft\gql\base\Resolver; -use craft\helpers\UrlHelper; use GraphQL\Type\Definition\ResolveInfo; +use nystudio107\retour\helpers\UrlHelper; use nystudio107\retour\Retour; /** @@ -75,6 +75,17 @@ public static function resolve($source, array $arguments, $context, ResolveInfo Retour::$plugin->statistics->incrementStatistics($uri, false, $siteId); } } + $dest = $redirect['redirectDestUrl']; + // If this isn't an absolute URL, make it one based on the appropriate site + if (!UrlHelper::isAbsoluteUrl($dest)) { + try { + $dest = UrlHelper::siteUrl($dest, null, null, $siteId); + $dest = parse_url($dest, PHP_URL_PATH); + } catch (Throwable $e) { + // That's ok + } + } + $redirect['redirectDestUrl'] = $dest; return $redirect; }