How does Drupal use these different terms? Route, Path, URL, URI, Link, Menu item
Saturday, January 31, 2015 - 12:29
Sometimes, diving in to try and help work on something in an open source project can leave you feeling stupid, lost and confused. Generally, you'll find you are not alone. Sharing the problem, and the solution when you find it, can be helpful to build your own understanding, but also might help others too. So, just in case I'm not the only one feeling lost and confused about why the path / route / link issue in Drupal is so complex, I thought I'd share some of my confusion and a little ray of light that might help unravel this tangle of related terminology.
In the Drupalverse, we use IRC to connect with each other. So I popped into channel and asked:
Can someone describe how drupal uses these terms? route, path, url, uri, link, menu item - or point me to a reference?
Angela Byron generously responded with a rough outline of definitions, which I've fleshed out a bit below with some references.
Route
"this URL goes to this PHP code, and can only be accessed by these kind of people."
As far as I can tell, this is a relatively new concept for Drupal with routing and controllers, replacing the hook-menu system we had previously. Here's a couple of references that might be helpful if you want to build a deeper understanding.
URL
Uniform Resource Locator eg. "https://www.drupal.org/community" It's generally the address we use to find content on the web.
URI
Uniform Resource Identifier is often confused with URL because it's so similar. See the URI wikipedia page for more information. I'm not sure if or how Drupal distinguishes between the use of URIs, URLs and URNs (Uniform Resource Names), but let's save that yak to shave on another day.
The Build a module team made a video that describes the difference between a URL and a URIWhat the difference is between a URI and a URL (a Drupal how-to)
Path
The path is like a pathway to find content eg. admin/content but because it can be an alias, it may not actually represent the location of a file on disk, which helps lead to some of the complexity under the hood in Drupal, and the confusion about when to use http://example.com/blog/yakshaving, /blog/yakshaving, or node/5
Link
<a href="/foo">foo</a> - This one seems pretty straightforward - it's the HTML markup used to point to a URI or path.
Menu item
A link in a menu - which could be pointing to a route, path or URI.
Hope that helps you, it certainly helps me to lay it all out like this. And, just in case you're wondering how I fell down this rabbit hole, this relates to a series of critical issues holding up the release of Drupal 8. If you can help, please get involved or buy a ticket in my chook raffle to help fund the Drupal 8 Accelerate initiative.