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 Tran 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
  • Phone/Zalo: (+84) 944 225 212
  • WhatsApp: (+84) 944 225 212
  • Line Messenger: (+84) 944 225 212
  • Email: asaleotestf@gmail.com
  • Telegram Messenger: https:/t.me/tommytran0401

Quảng cáo việc làm

 

Thích hợp các bạn nữ mảng thợ may làm việc tại nước NGA

Đơn hàng Tuyển dụng 100 Thợ may đi Nga(đợt 1 tháng 3.2021, đợt 2 tháng 5.2021). Lương thực lãnh 800 USD, bao ăn ở, vé máy bay và visa, phí xuất cảnh(1800 USD)trả khi đi làm có lương. Bạn có thể liên hệ CÔNG TY qua Phone/Zalo: (+84) 944 225 212. Công ty sẽ tư vấn cho bạn.

Xem chi tiết: >>> https://bit.ly/3o9NOfR

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

 
Bóng ma xuất hiện ở nghĩa địa giữa ban ngày

Bóng ma xuất hiện ở nghĩa địa giữa ban ngày

Mặc dù giữa ban ngày, nhưng ông John Finch vẫn khẳng định, hồn ma xuất hiện trong bức ảnh chính là nguyên nhân khiến ông cảm thấy lạnh gáy.

Facebook bổ sung nút Subscribe lấn sân Twitter và Google+

Facebook bổ sung nút Subscribe lấn sân Twitter và Google+

Facebook đang mở rộng phạm vi mạng xã hội của mình, lấn sang “lãnh địa” của Twitter và Google+ bằng cách làm cho các thành viên Facebook có thể đăng ký theo dõi (subscribe) ...

Giới thiệu ví dụ đơn giản AJAX Example trong Drupal 6, Drupal 7

Giới thiệu ví dụ đơn giản AJAX Example trong Drupal 6, Drupal 7

It should go without saying but I find many of those asking for help on ajax are not sure what to do with all the hooks and such necessary to implement an ajax callback.