0

Can I generate a

https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Url.php/class/Url/8.2.x

from a simple path, e.g. "/products/widget" ?

(assume /products/widget exists in the system and is a canonical path)

1

Use Url:fromRoute () and pass in the route's name and arguments. You can also use fromUri() for external paths. https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Url.php/function/Url%3A%3AfromRoute/8.2.x

I usually find the route name by searching the routing.yml files for the path.

Alternately, you can do this. How to get the Route object from an URI?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.