Add helper to get the path from the master request

Created on 15 July 2015, almost 10 years ago
Updated 21 May 2025, 13 days ago

Problem/Motivation

As seen in #2532174: Access the parent/master request of a sub request β†’ there are cases where we need to access the path of the master request (put a login form on a 403 error page, use the path of a 404 error to trigger a search in the content, etc.). Currently, that's possible by writing something like:

$request_stack = \Drupal::service('request_stack');
$current_path = \Drupal::service('path.current');

$path = $current_path->getPath($request_stack->getMasterRequest());

That kind of usage is hard to document and is not good for DX. Moreover, the path.current already has access to the request_stack service so we could remove one dependency in that case.

Proposed resolution

Add an helper on the path.current service.
We could have for example:

$current_path = \Drupal::service('path.current');
$path = $current_path->getMasterPath();

Remaining tasks

Name the helper, write the code.

User interface changes

None.

API changes

Yes, TBD.

Data model changes

None.

✨ Feature request
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

request processing system

Created by

πŸ‡«πŸ‡·France duaelfr Montpellier, France

Live updates comments and jobs are added and updated live.
  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

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.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for sharing your idea for improving Drupal.

    We are working to decide if this proposal meets the Criteria for evaluating proposed changes. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or there is no community support. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

  • πŸ‡«πŸ‡·France duaelfr Montpellier, France

    TBH, I don't remember why I needed this such a long time ago.
    I just checked 11.x code and this has not been implemented yet.
    Creating this new method wouldn't impact existing code and wouldn't need any new dependency. It'd be a pure helper for DX.

    Given the lack of comments here. I guess this is not really needed by anyone ;)
    Let's see.

Production build 0.71.5 2024