class RoleAccessCheck

Same name in other branches
  1. 3.x modules/menu_example/src/Access/RoleAccessCheck.php \Drupal\menu_example\Access\RoleAccessCheck
  2. 8.x-1.x 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

Expanded class hierarchy of RoleAccessCheck

See also

https://www.drupal.org/docs/8/api/routing-system/access-checking-on-rou…

1 string reference to 'RoleAccessCheck'
menu_example.services.yml in modules/menu_example/menu_example.services.yml
modules/menu_example/menu_example.services.yml
1 service uses RoleAccessCheck
menu_example.access_check.role in modules/menu_example/menu_example.services.yml
Drupal\menu_example\Access\RoleAccessCheck

File

modules/menu_example/src/Access/RoleAccessCheck.php, line 23

Namespace

Drupal\menu_example\Access
View 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

Title Sort descending Modifiers Object type Summary
RoleAccessCheck::access public function Checks access.