function user_access_test_user_access

Same name in other branches
  1. 8.9.x core/modules/user/tests/modules/user_access_test/user_access_test.module \user_access_test_user_access()
  2. 10 core/modules/user/tests/modules/user_access_test/user_access_test.module \user_access_test_user_access()
  3. 11.x core/modules/user/tests/modules/user_access_test/user_access_test.module \user_access_test_user_access()

Implements hook_ENTITY_TYPE_access() for entity type "user".

File

core/modules/user/tests/modules/user_access_test/user_access_test.module, line 17

Code

function user_access_test_user_access(User $entity, $operation, $account) {
    if ($entity->getAccountName() == "no_edit" && $operation == "update") {
        // Deny edit access.
        return AccessResult::forbidden();
    }
    if ($entity->getAccountName() == "no_delete" && $operation == "delete") {
        // Deny delete access.
        return AccessResult::forbidden();
    }
    // Account with role sub-admin can manage users with no roles.
    if (count($entity->getRoles()) == 1) {
        return AccessResult::allowedIfHasPermission($account, 'sub-admin');
    }
    return AccessResult::neutral();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.