From 4a89652f3e248d89dcdab2ac4f48d16d664c12dc Mon Sep 17 00:00:00 2001 From: Daniel Bosen Date: Tue, 7 May 2024 17:21:53 +0200 Subject: [PATCH] Revert "Reapply "Fix redirect settings"" This reverts commit 3ddc589cd341958d787e0f3f69cb4b71c759c19a. --- .../GraphQL/DataProducer/ThunderRedirect.php | 50 +++++++------------ 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderRedirect.php b/modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderRedirect.php index 3a32edbc9..7eb44edf2 100644 --- a/modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderRedirect.php +++ b/modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderRedirect.php @@ -3,7 +3,6 @@ namespace Drupal\thunder_gqls\Plugin\GraphQL\DataProducer; use Drupal\Core\Cache\RefinableCacheableDependencyInterface; -use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Path\PathValidatorInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -49,7 +48,6 @@ public static function create(ContainerInterface $container, array $configuratio $container->get('language_manager'), $container->get('path.validator'), $container->get('renderer'), - $container->get('config.factory'), $container->get('redirect.repository', ContainerInterface::NULL_ON_INVALID_REFERENCE), ); } @@ -69,8 +67,6 @@ public static function create(ContainerInterface $container, array $configuratio * The path validator. * @param \Drupal\Core\Render\RendererInterface $renderer * The renderer service. - * @param \Drupal\Core\Config\ConfigFactory $config - * The config. * @param \Drupal\redirect\RedirectRepository|null $redirectRepository * The redirect repository. * @@ -83,7 +79,6 @@ public function __construct( protected LanguageManagerInterface $languageManager, protected PathValidatorInterface $pathValidator, protected RendererInterface $renderer, - protected ConfigFactory $config, protected ?RedirectRepository $redirectRepository = NULL, ) { parent::__construct($configuration, $pluginId, $pluginDefinition); @@ -104,9 +99,6 @@ public function resolve(string $path, RefinableCacheableDependencyInterface $met $metadata->addCacheTags(['redirect_list']); if ($this->redirectRepository) { - $redirectConfig = $this->config->get('redirect.settings'); - $metadata->addCacheTags($redirectConfig->getCacheTags()); - $queryString = parse_url($path, PHP_URL_QUERY) ?: ''; $pathWithoutQuery = parse_url($path, PHP_URL_PATH) ?: $path; @@ -132,30 +124,26 @@ public function resolve(string $path, RefinableCacheableDependencyInterface $met 'status' => $redirect->getStatusCode(), ]; } + } - if ($redirectConfig->get('route_normalizer_enabled')) { - // Ensure the path starts with a slash, fromUserInput fails otherwise. - if (!str_starts_with($path, '/')) { - $aliasPath = '/' . $path; - } - else { - $aliasPath = $path; - } - $context = new RenderContext(); - $alias = $this->renderer->executeInRenderContext($context, function () use ($aliasPath): string { - return Url::fromUserInput($aliasPath)->toString(); - }); - if (!$context->isEmpty()) { - $metadata->addCacheableDependency($context->pop()); - } - - if ($alias !== $path) { - return [ - 'url' => $alias, - 'status' => $redirectConfig->get('default_status_code'), - ]; - } - } + // Ensure the path starts with a slash, fromUserInput fails otherwise. + if (!str_starts_with($path, '/')) { + $aliasPath = '/' . $path; + } + else { + $aliasPath = $path; + } + + $context = new RenderContext(); + $alias = $this->renderer->executeInRenderContext($context, function () use ($aliasPath): string { + return Url::fromUserInput($aliasPath)->toString(); + }); + + if ($alias !== $path) { + return [ + 'url' => $alias, + 'status' => 301, + ]; } if (($url = $this->pathValidator->getUrlIfValidWithoutAccessCheck($path)) && $url->isRouted()) {