Improve documentation on the working of Url::fromUserInput

Created on 11 June 2019, over 5 years ago
Updated 4 February 2023, almost 2 years ago

Problem/Motivation

Currently it's not clear whether Url::fromUserInput expect a URL relative to the Drupal root, or relative to the host.

In 99% of the cases this is the same, but when installing Drupal in a subdirectory this is not the same.

If Drupal is installed in example.com/subdirectory one might understand that it's possible to pass the url relative to the host to Url::fromUserInput (/subdirectory/whatever-route). This however should never happen, as it results in incorrectly parsed Url strings. (subdirectory/subdirectory/whatever-route)

The fact that this is not documented, and the fact that the testbot in some cases doesn't actually fail, leads to problems: see the related issues.

Proposed resolution

As said, there is no way of stripping out the subdirectory within current API. This is because the 'fromUserInput' can come from various sources which might or might not include the subdirectory. When that subdirectory is, say, 'admin', and the drupal relative url is also 'admin', there is no way to know what to strip away.

Proposed solution is to at least make sure that this is properly documented and that there is a clear pattern/helper of how to strip away the subdirectory if necessary.

Remaining tasks

  1. Update the documentation comment in Url::fromUserInput.
  2. Find where this might be documented on Drupal.org
  3. Update/comment all issues that might be related to this project.
  4. Create/find issue to create a helper method to strip away subdirectories when needed
  5. Create/link issue about the not-failing tests when there is a subdirectory
πŸ“Œ Task
Status

Postponed: needs info

Version

10.1 ✨

Component
RoutingΒ  β†’

Last updated 2 days ago

Created by

πŸ‡ͺπŸ‡ΈSpain nuez Madrid, Spain

Live updates comments and jobs are added and updated live.
  • Documentation

    Primarily changes documentation, not code. For Drupal core issues, select the Documentation component instead of using this tag. In general, component selection is preferred over tag selection.

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.

Production build 0.71.5 2024