OutboundPathProcessorInterface does not correctly handle absolute urls anymore

Created on 27 April 2017, about 7 years ago
Updated 10 February 2023, over 1 year ago

Having a field in a node with a given url, this code does not work anymore. It did in version 8.2.7.


namespace Drupal\mymodule\PathProcessor;

use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\PathProcessor;
use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
use Drupal\node\Entity\Node;
use Symfony\Component\HttpFoundation\Request;

class MymoduleFieldRedirectPathProcessor implements OutboundPathProcessorInterface {

  public function processOutbound($path, &$options = array(), Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {

    if (isset($options['entity']) && is_object($options['entity']) && method_exists($options['entity'], 'hasField')) {
      $node = $options['entity'];
      
      if ($node->hasField('field_project_url') && !$node->field_project_url->isEmpty()) {
        $project_url = $node->field_project_url->getValue();

        if (preg_match("/^\/node\/[0-9]+\/(edit|translate|delete|translations)$/i", $path)) {
          // dont alter operational paths
        }
        else {
          $path = $project_url[0]['uri'];

          $options['absolute'] = TRUE;
          $options['external'] = TRUE;
          $options['base_url'] = '';
          $options['prefix'] = '';
        }

        if ($bubbleable_metadata) {
          $bubbleable_metadata->addCacheableDependency($node);
        }
      }
    }
    return $path;
  }

}

The url now looks like this:

localhost:8888/mysite/de/http%3A//www.urlfromfield.com

instead of

http://www.urlfromfield.com

I wonder if this somehow relates to https://drupal.stackexchange.com/questions/234782/is-the-field-file-toke...

πŸ› Bug report
Status

Closed: works as designed

Version

9.5

Component
PathΒ  β†’

Last updated 6 days ago

  • Maintained by
  • πŸ‡¬πŸ‡§United Kingdom @catch
Created by

πŸ‡©πŸ‡ͺGermany sic

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡³πŸ‡ΏNew Zealand quietone New Zealand

    Further information has not been supplied. Time to close this one.

    If you encounter this problem, open a new issue and refer to this one. Thanks

Production build 0.69.0 2024