hook_entity_access doesn't fire on add operation

Created on 25 May 2018, over 6 years ago
Updated 19 August 2024, 3 months ago

I want to handle my eck entity types access trough hook_entity_access() because I need dynamic permissions. It works on operations "view" and "update". But on creating... the hook doesn't fire. It works with nodes for example.

Steps:
1. Create eck entity type.
2. Create eck entity bundle
3. Create eck entity bundle text field.
4. Add hook_entity_access() to a custom module and check if the hook is working.
5. Try to add a eck entity. (/admin/content/entity_type/add/entity_bundle)
6. Result: No access control over the hook.

My question: Why? Is it a bug?

Drupal: 8.5.0
ECK: 8.x-1.0-alpha3+8-dev

🐛 Bug report
Status

Closed: works as designed

Version

1.0

Component

Code

Created by

🇨🇭Switzerland handkerchief

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇳🇿New Zealand garethhallnz

    I just encountered this problem too. After some debugging, I discovered that the issue was due to having the "bypass ECK entity access" permission. When you have this permission, the hook_entity_access is never called.

    As per /src/EckEntityAccessControlHandler.php#L52

      public function access(EntityInterface $entity, $operation, AccountInterface $account = NULL, $return_as_object = FALSE) {
        if ($this->canBypassAccessCheck($account)) {
          return $this->getBypassAccessResult($return_as_object);
        }
        else {
          return parent::access($entity, $operation, $account, $return_as_object);
        }
      }
    
Production build 0.71.5 2024