Problem/Motivation
I am trying to use the OutboundPathProcessorInterface so that when a user clicks this link: '/node/7849', he is redirected to this URL:
'https://churchages.net/en/sermon/wesley/laying-the-foundation-of-the-new...';
If I do NOT use $options['absolute'] = TRUE, I get the full URL of my site prepended to the link output:
https://bible.booksai.org/node/https%3A/churchages.net/en/sermon/wesley/...
If I DO use $options['absolute'] = TRUE, I get nothing at all. When I hoover over the link, nothing appears. When I click on it, it takes me to a blank page: about:blank#blocked
Steps to reproduce
Created the class file:
namespace Drupal\solrai\PathProcessor;
use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
use Symfony\Component\HttpFoundation\Request;
class MyOutboundPathProcessor implements OutboundPathProcessorInterface {
public function processOutbound($path, &$options = [], Request $request = NULL, $bubbleable_metadata = NULL) {
// Check if the path is in your table
$result = $this->lookupPathInTable($path);
// If a matching destination path is found, replace it and set external if needed
if ($result) {
$path = $result['path'];
if ($result['absolute']) {
$options['absolute'] = TRUE;
}
}
return $path;
}
private function lookupPathInTable($path) {
// Define the mappings of paths to their respective URLs
$pathMappings = [
'/node/7849' => 'https://churchages.net/en/sermon/wesley/laying-the-foundation-of-the-new-chapel/',
'/node/7850' => 'https://churchages.net/en/sermon/wesley/death-of-rev-mr-john-fletcher/'
];
// Check if the path exists in the mapping
if (array_key_exists($path, $pathMappings)) {
return [
'path' => $pathMappings[$path],
'absolute' => TRUE
];
}
// Return null if no matching path is found
return null;
}
}
In the class file, if the incoming $path matches a mapping in my lookupPathInTable($path) method, then I return the external URL with $options['absolute'] = TRUE. However, this results in NO link: about:blank#blocked
All of the documentation I have found so far appear to state that the above is the way to redirect to an external URL using OutboundPathProcessorInterface, but it's not working.
Proposed resolution
If this is a bug, has it been resolved in newer core versions? If not, how do I resolve?