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

  • 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.
    – mona lisa
    Commented Dec 6, 2022 at 13:54
  • I have updated with the handler code
    – CWolf18
    Commented 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
    Commented Dec 6, 2022 at 14:20
  • Already done with drush cr
    – CWolf18
    Commented 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
    Commented Dec 12, 2022 at 15:31


Your Answer

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

Browse other questions tagged or ask your own question.