Drupal core allows access to /admin/people/create based on the permission 'administer users'. This is correct by default, in vanilla core. However it ignores any code that has implemented hook_entity_create_access.
This issue is a blocker for contrib module Administer Users by Role.
Steps to reproduce
- Create a custom modules that implements
hook_entity_create_access
as below (plus XXX.permissions.yml to define the new permission). - Create a user with permission 'create users' and log on as that user.
- Visit /admin/people/create
- Expected behaviour: can access page.
- Actual behaviour: access denied.
function XXX_entity_create_access(AccountInterface $account, array $context, $entity_bundle) {
if ($context['entity_type_id'] != 'user') {
return AccessResult::neutral();
}
return AccessResult::allowedIfHasPermission($account, 'create users');
}
Resolution
If the requirement is changed to _entity_create_access: 'user'
it works perfectly. The new code is consistent with a variety of other places in Drupal Core.