Score:1

Inbound path processor is not processing

cn flag

I'm trying to use an Inbound Path Processor to redirect a path(to a webapp based on this tutorial), but Drupal is not picking it up.

I tried the following code to simply redirect every page on the site to /happy, but after rebuilding the cache, nothing happens; I can navigate the site normally and never get redirected.

/mymodule/src/PathProcessor/MyPathProcessor.php

namespace Drupal\mymodule\PathProcessor;

use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Symfony\Component\HttpFoundation\Request;

class MyPathProcessor implements InboundPathProcessorInterface {

  public function processInbound($path, Request $request) {
    return '/happy';
  }

}

Am I using this wrong? What do I need to do to get Drupal to use the path processor?

4uk4 avatar
cn flag
This is not a redirect by the way. Path processing is like rewriting in .htaccess without `[R,L]`. If you want to rewrite the path with a redirect you can use an event subscriber. See https://www.drupal.org/node/2013014
Score:2
us flag

A path processor is a service tagged with path_processor_inbound. For example, this is the definition of the path_processor.files path processor used by Drupal core.

path_processor.files:
  class: Drupal\system\PathProcessor\PathProcessorFiles
  tags:
    - { name: path_processor_inbound, priority: 200 }

Keep in mind that all the path processors are invoked. If the path set by a path processor isn't used from Drupal, another path processor could have changed it. Services like path_processor.files use the priority for that reason: to avoid conflicts with other services of the same type which, in this case, could change the path already altered by another path processor.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.