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
-
Update the documentation comment in
Url::fromUserInput
.
-
Find where this might be documented on Drupal.org
-
Update/comment all issues that might be related to this project.
- Create/find issue to create a helper method to strip away subdirectories when needed
- Create/link issue about the not-failing tests when there is a subdirectory