Skip to content

Commit

Permalink
Revert "Reapply "Fix redirect settings""
Browse files Browse the repository at this point in the history
This reverts commit 3ddc589.
  • Loading branch information
dbosen committed May 7, 2024
1 parent 3ddc589 commit 4a89652
Showing 1 changed file with 19 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
);
}
Expand All @@ -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.
*
Expand All @@ -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);
Expand All @@ -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;

Expand All @@ -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()) {
Expand Down

0 comments on commit 4a89652

Please sign in to comment.