Version 1
[yaffs-website] / web / core / modules / user / src / RoleAccessControlHandler.php
1 <?php
2
3 namespace Drupal\user;
4
5 use Drupal\Core\Access\AccessResult;
6 use Drupal\Core\Entity\EntityAccessControlHandler;
7 use Drupal\Core\Entity\EntityInterface;
8 use Drupal\Core\Session\AccountInterface;
9
10 /**
11  * Defines the access control handler for the user role entity type.
12  *
13  * @see \Drupal\user\Entity\Role
14  */
15 class RoleAccessControlHandler extends EntityAccessControlHandler {
16
17   /**
18    * {@inheritdoc}
19    */
20   protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
21     switch ($operation) {
22       case 'delete':
23         if ($entity->id() == RoleInterface::ANONYMOUS_ID || $entity->id() == RoleInterface::AUTHENTICATED_ID) {
24           return AccessResult::forbidden();
25         }
26
27       default:
28         return parent::checkAccess($entity, $operation, $account);
29     }
30   }
31
32 }