class RoleAccessCheck in Examples for Developers 8
Same name and namespace in other branches
- 3.x modules/menu_example/src/Access/RoleAccessCheck.php \Drupal\menu_example\Access\RoleAccessCheck
Determines access to routes based on roles.
To achieve this, we implement a class with AccessInterface and use that to check access.
Our module is called menu_example, this file will be placed under menu_example/src/Access/CustomAccessCheck.php.
The menu_example_services.yml contains entry for this service class.
Hierarchy
- class \Drupal\menu_example\Access\RoleAccessCheck implements AccessInterface
Expanded class hierarchy of RoleAccessCheck
See also
https://www.drupal.org/docs/8/api/routing-system/access-checking-on-routes
1 string reference to 'RoleAccessCheck'
- menu_example.services.yml in menu_example/
menu_example.services.yml - menu_example/menu_example.services.yml
1 service uses RoleAccessCheck
File
- menu_example/
src/ Access/ RoleAccessCheck.php, line 23
Namespace
Drupal\menu_example\AccessView source
class RoleAccessCheck implements AccessInterface {
/**
* Checks access.
*
* @param \Drupal\Core\Session\AccountInterface $account
* The currently logged in account.
*
* @return string
* A \Drupal\Core\Access\AccessInterface constant value.
*/
public function access(AccountInterface $account) {
// If the user is authenticated, return TRUE.
return AccessResult::allowedIf($account
->isAuthenticated());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RoleAccessCheck:: |
public | function | Checks access. |