March 2019
Intermediate to advanced
580 pages
15h 3m
English
If we defined routes, and users go to those routes, Drupal would check access for us automatically (according to the requirements set forth in the route definition). However, we may often need to check access to a given route programmatically, for example, to know whether we should show a link to it to the current user.
In Chapter 2, Creating Your First Module, we saw how to work with Url objects to create links, and we can use these very Url objects to check access on a given route; consider the following example:
$url = Url::fromRoute('hello_world.hello');
if ($url->access()) {
// Do something.
}
The access() method on the Url object works only with routed URLs, those which have been determined ...
Read now
Unlock full access