It is not easy to debug access denied in Drupal (especially in views), This is why I have added a lot of "reasons" when using AccessResult::forbidden($reason);

Unfortunately, when an access Denied arise, I couldn't find any log or anything else in which the Reason was properly outputted to give me a clue on why this acces was Denied.

Note: As pointed out by @Clive, if the access is calculated to display a page/route, it will be displayed in the 403 response. My question is not about this kind of access, my question is about (for example) entity access (ex: view or edit a user)

Am I missing something?

  • Looks like it'll be in the body of the 403 response itself – Clive May 21 at 13:33
  • I assume you are right if the access is calculated to display a page/route. In my case it is to display users. I will update my question. – Baud May 21 at 13:47
  • 1
    My (admittedly quick) scan of the classes would suggest the output of getReason() is only ever used by core when it’s sent back to the client as part of the response, or as part of a test assertion - conceptually I suppose if you’re the one consuming the code, you’re also responsible for checking the reason and logging it if you need to, and core didn’t deem that necessary in the other scenarios. Don’t quote me on it though :) – Clive May 21 at 13:54
  • I think you have answered my question. Thank you!! – Baud May 21 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.