2

I have set a handler for the access of my entity but when I reference it in another entity, the access is not checked. I want the reference and the entity to have the same access check. Any idea ? The entity is a taxonomy term and I reference it in a basic node

The handler below, I return forbidden to test

/**
 * Defines the access control handler for the taxonomy term entity type.
 *
 * @see \Drupal\taxonomy\Entity\Term
 */
class MyAccessControlHandler extends TermAccessControlHandler {

  /**
   * {@inheritdoc}
   */
  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
    return AccessResult::forbidden();
  }

}

Edit : Until I found a better solution, I use view and form alter hook to check the referenced entity access by getting the said entity and using it's access() method

11
  • Welcome to Drupal Answers! If there is some custom code you must add that to the question or the question will be downvoted. I wish to make to aware that Drupal 8 is end-of-life and is no longer developed or supported on drupal.org.
    – cilefen
    Dec 6, 2022 at 13:54
  • I have updated with the handler code
    – CWolf18
    Dec 6, 2022 at 14:04
  • Drupal caches access results, causing access check code to not be hit. Clear caches or disable caching while debugging to eliminate this possibility.
    – Joseph
    Dec 6, 2022 at 14:20
  • Already done with drush cr
    – CWolf18
    Dec 6, 2022 at 14:23
  • 1
    Access handlers are only on CRUD actions directly on the entity. If you are adding the entity as a reference, you need to put permissions on that field. The field permission module will probably help.
    – Jaypan
    Dec 12, 2022 at 15:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.