Skip to content

Latest commit

 

History

History
81 lines (66 loc) · 3.69 KB

access.md

File metadata and controls

81 lines (66 loc) · 3.69 KB

Custom access control to a page

Goals

  • Provide a page at /user/$uid/identity which displays the user's name and email.
  • Every user should be able to access only his/her own page.
  • Provide a tab at /user/$uid that's displayed only on the user's own profile.

Prerequisites

If you're a newcomer to Drupal 8, you should learn how to create A "Hello World" Custom Page Module.

Drupal 7

Adding a custom access callback to a D7 router item consists of two steps.

As Drupal 7's caching system is not that sophisticated as the one in Drupal 8, we don't and can't provide caching-related information.

Drupal 8

Adding a custom access callback to a D8 router item consists of quite some steps.

In addition to the access checking decision, the same function provides the information to Drupal 8's caching system that the pages governed by this access checking mechanism should only be [cached per user] (https://github.com/boobaa/d7to8/blob/master/d8/d8access/src/Access/OwnDataAccessCheck.php#L33). Later on, the controller that builds the render array informs the caching system that the information provided by it [should not be cached] (https://github.com/boobaa/d7to8/blob/master/d8/d8access/src/Controller/D8AccessDisplayController.php#L27-L30) at all. (In our particular case it's not 100% required, but we're including this to shed light to this corner of the caching system as well.)

References

To understand why and how this routing and access checking works, check these resources: