Active
Project:
Drupal core
Version:
main
Component:
base system
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
10 May 2016 at 10:55 UTC
Updated:
26 Aug 2020 at 08:46 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #5
geekygnr commentedI ran into this problem as well from a Url object that was generated with the Url::fromRoute function.
It looks like the Url::getUri() function is a straight getter function for the variable on the object. I also found a Url::toUriString() function that worked well.
Not sure what the use case is for having these two functions. I would expect the two functions to return the same thing always making them redundant.
Comment #7
ericmulder1980 commentedI came here after searching for a problem with
This resulted in the error "This URL has a Drupal route, so the canonical form is not a URI" as stated by the OP.
So when you want to get the Uri (path) for a specific route the code below seems to work.
This returns "/user/login"
This returns "user/login"
Why would Url:fromRoute() not use the urlGenerator to create a full Url object?
Kind regards,
Eric Mulder
Comment #12
blanca.esqueda commentedI'm trying to get the URI schema from an entity.
using: $referenced_entity->toUrl()->getUri();
triggers the error "This URL has a Drupal route, so the canonical form is not a URI".
using: $referenced_entity->toUrl()->toUriString();
returns the route: route:entity.node.canonical;node=16
instead of the uri schema: entity:node/16
I've tried in different ways but it seems like I can not get the URI schema from an entity.
Some help would be appreciated.
Comment #13
blanca.esqueda commentedAs a solution, I propose getUri() to return the URI instead of the error: 'This URL has a Drupal route, so the canonical form is not a URI'
getUri() in https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Url.php/c...
would change to something like this:
Comment #14
qandeel commentedInstead of updated getUri(); I would suggest to have a new public function dealing with this new functionality, I have created a patch for this; drupal core 8.9.2