I want to perform a custom access check for every page load.

For this purpose I implement AccessCheckInterface and perform the checks in the access method. AccessCheckInterface has a method applies, which returns an array of route requirement keys for which the access check is performed, as far as I understand.

Unfortunately, I have no idea what route requirement keys are and where to find them.

Currently, I simply return TRUE, which results in the access method being called several dozen times per page load. I would like this access check being done only once per page load as I have to perform an expensive network query. Is there a route requirement key for this? Can this be done in a different way?

  • 1
    Just store the results of the expensive query in a static variable and re-use – Clive Dec 6 at 12:10
  • Thank you Clive, that's a good idea! However, I might get different results over time. – drupalnewbie Dec 6 at 12:16
  • I take that back. This works! Thank you again, @Clive! – drupalnewbie Dec 6 at 12:36

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.