March 2019
Intermediate to advanced
580 pages
15h 3m
English
The static approach involves creating a method on our Controller (or somewhere else), usually called access(), and referencing it from the route definition. So, inside our controller we can have this:
/**
* Handles the access checking.
*
* @param \Drupal\Core\Session\AccountInterface $account
*
* @return \Drupal\Core\Access\AccessResultInterface
*/
public function access(AccountInterface $account) {
return in_array('editor', $account->getRoles()) ? AccessResult::forbidden() : AccessResult::allowed();
}
And the new use statements:
use Drupal\Core\Access\AccessResult; use Drupal\Core\Session\AccountInterface;
This method receives the current user's AccountInterface, which we can use to determine the roles. Moreover, if we ...
Read now
Unlock full access