2

I would like to change url for secure token. Now it /webform/MYFORM/submissions/sid?token

But i would like to change it to /submissions/sid?token

I use these instructions https://www.drupal.org/project/webform/issues/2979091 but could't modify path. If I use OutboundPathProcessorInterfaceI get 404.

How can I achieve this?

WHAT I'VE DONE

I create mymodule.services.yml with:

services:
  mymodule.link_modifier_service:
    class: Drupal\mymodule\LinkModifierService
    tags:
      - { name: path_processor_inbound, priority: 300 } 
      - { name: path_processor_outbound, priority: 300 }  
    arguments: ['@request_stack']

Put in src folder LinkModifierService.php with:

<?php

namespace Drupal\mymodule;
use Symfony\Component\HttpFoundation\RequestStack;
use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Render\BubbleableMetadata;


/**
 * Class DefaultService.
 */
class LinkModifierService implements InboundPathProcessorInterface, OutboundPathProcessorInterface {

  /**
   * Symfony\Component\HttpFoundation\RequestStack definition.
   *
   * @var \Symfony\Component\HttpFoundation\RequestStack
   */
  protected $requestStack;
  /**
   * Constructs a new DefaultService object.
   */
  public function __construct(RequestStack $request_stack) {
    $this->requestStack = $request_stack;
  }
  
  /**
   * {@inheritdoc}
   */
  public function processInbound($path, Request $request = NULL) {
    if (strpos($path, '/submission/') === 0) {
      $sid = str_replace('/submission/', '', $path);
      $path = "/webform/MYFORM/submissions/" . $sid;
    }
    return $path;
  }  
  
  /**
   * {@inheritdoc}
   */
  public function processOutbound($path, &$options = array(), Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
  
    if (empty($request)) {
      $request = $this->requestStack->getCurrentRequest();
    }
    if (strpos($path, '/webform/MYFORM/submissions/') === 0) {
      $sid = str_replace('/webform/MYFORM/submissions/', '', $path);
      $path = "/submission/" . $sid;
    }

    return $path;
  }
  
}

Now I could get /submission/sid?tokenbut I could't change first part of this url. I need MYFORM/sid?token without word 'submission'.

2
  • Those are not instructions. They are the maintainer saying that people should write custom code and people posting some things that they tried. As written this question is unanswerable because we don’t know what you did.
    – mona lisa
    Commented Jul 10, 2022 at 11:48
  • I add all I've done in my question and I just need to change 'submission' in fron of url.
    – kazah
    Commented Jul 10, 2022 at 13:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.