Sự khác nhau Route, Path, URL, URI, Link, Menu item trong Drupal 8

Sự khác nhau Route, Path, URL, URI, Link, Menu item trong Drupal 8

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.

>> Giới thiệu PHP và JavaScript Closures, cài đặt Drupal 8

>> Hội thảo Drupal 8 xoay quanh sprint designed tại Belgium

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.

update: Peter Wolanin wrote to say 

In D6 & D7 the menu system was the routing system. "this is a relatively new concept for Drupal" is not correct. We re-wrote things in terms of Symfony classes, but the basic concepts are actually the same. In Drupal 7 the data is stored in the {menu_router} table, in D8 it's been moved to just {router}. The big different in Drupal 8 vs D7 is that a single path may match more than one route name. In D7 a path is identical to the route name, so there cannot be more than one.

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 URI
What the difference is between a URI and a URL (a Drupal how-to)

update: Peter adds

Recent patches landing in core have adopted a URI field for storage for the Link Field, so you will (in the database at least) now start to see URIs like entity:node/5 and user-path:/blog

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

update: Peter notes 

The Path section should mention at least the idea of "base path" - the prefix including the subdirectory that needs to be adding to an "internal path" to make a relative URL. It would also be worth noting that by adopting the new routing system we are trying to remove, as much as possible, use of or reference to the internal path in favor of routes when referring to a Drupal page.

and

the base path will usually just be a "/" unless Drupal is installed in a subdirectory.

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.

update: and final note

The term "menu item" here is wrong. It should be "menu link". In D6 & D7 a "menu item" is the thing that's been replaced by a "route object" in D8. However, I will acknowledge that in D6 and D7 there is a lot of code that may use variables or comments referring to a menu link as a menu item - this is generally a reflection of logic carried forward from D5 where they were actually the same thing.

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.

Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Hướng dẫn Drupal 7: Load content nodes vào modal overlay sử dụng AJAX

Hướng dẫn Drupal 7: Load content nodes vào modal overlay sử dụng AJAX

AJAX to the rescue.  By loading each of the individual content nodes "on demand" we can cut the unnecessary burden of loading everything up front, and only load the content that is actually requested by the visitor

 10 Homescreen đẹp nhất năm 2011

10 Homescreen đẹp nhất năm 2011

Trang web MyColorScreen - 1 trang web cho phép người dùng chia sẻ homescreen của smartphone và tablet của mình - đã bình chọn ra 10 homescreen đẹp nhất...

Phong thủy công ty: Ban công và 5 điều kỵ

Phong thủy công ty: Ban công và 5 điều kỵ

Ban công đối thẳng với đường đi hoặc cửa ra vào bị coi là bất lợi về mặt phong thủy.

Công ty diệt chuột T&C

 

Diet con trung