RoleAccessControlHandler.php 823 B

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