I have a node node/1
with the path alias /path
. What I want is for /path/*
to always behave like you went to /path
, but not change the url. So going to /path/test?something=1
should behave identically to going to /path
but the url will still be /path/test?something=1
in the user's browser.
Right now, I'm getting a redirect loop when I return the same url in the processOutbound
method. If I just return $path
in this method, the user gets redirected to /path?something=1
.
My use case is a vue app that has it's own routing. But we need a node to allow the client to edit the content around the app.
Code below. Thanks!
<?php
namespace Drupal\gm_custom;
use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
use Drupal\Core\Render\BubbleableMetadata;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
class PathSubscriber implements InboundPathProcessorInterface, OutboundPathProcessorInterface
{
/**
* Processes the inbound path.
*
* @param string $path
* The path to process, with a leading slash.
* @param \Symfony\Component\HttpFoundation\Request $request
* The HttpRequest object representing the current request.
*
* @return string
* The processed path.
*/
public function processInbound($path, Request $request)
{
if ($this->stringStartsWith('/plan/', strtolower($path))) {
return '/node/1';
}
return $path;
}
public function processOutbound(
$path,
&$options = [],
Request $request = null,
BubbleableMetadata $bubbleable_metadata = null
) {
$url = strtok($_SERVER[ "REQUEST_URI" ], '?');
if ($this->stringStartsWith('/plan/', $_SERVER[ 'REQUEST_URI' ])) {
return $url;
}
return $path;
}
protected function stringStartsWith($needle, $haystack)
{
return (substr($haystack, 0, strlen($needle)) === $needle);
}
}
Edit I've confirmed it's the redirect module is the issue. Simply installing it creates the above problem. Still looking for a solution.