The AccessPluginBase class which is extended for Permission Plugins in Views uses the method access() and returns TRUE or FALSE depending upon whether the user should have access to the view.
The return value is cached. That means that it isn't possible to use these plugins on each and every page load to determine whether the user has access or not. Any system which is using external authentication for anonymous traffic and not Drupal's built-in authentication (such as cookies, paywall / content protection systems that poll external APIs) will not function correctly unless the Drupal cache is repeatedly cleared which of course isn't practical.
Is this a bug or is there a way to force the page to call access() every time in the Plugin?
The problem can be reproduced easily - select one of the three built-in permissions (such as None.php) and insert a drupal_set_message('Hello world'); before the Boolean return in access(). Then set up a View to use that permission, clear the cache, and land on the page. You will see the "Hello World" first time but not on subsequent page loads until the cache is cleared again.
Also worth mentioning I am using public function getCacheMaxAge() { return 0; } but it doesn't appear to work.
Comments
Comment #2
badzilla commentedComment #3
mustanggb commentedComment #5
matiasmirandaYour workaround helped me a lot (for now) thanks @badzilla http://www.badzilla.co.uk/drupal-8-views-custom-access-plugin.
following for final solution...
Comment #7
fconnolly commentedany update on this?
Comment #11
vivek panicker commentedThis should be a bug.
I am facing the same issue in Drupal 8.8.10.
Comment #12
vivek panicker commentedComment #13
pameeela commentedThe issue should be against the bug fix branch, and it will be backported where possible.
Comment #19
quietone commented@badzilla, thanks for the report and especially including the steps to reproduce!
I tested this on a fresh install of Drupal 11.x, standard install. I followed the steps in the issue summary and the test message was displayed on every page load. In other words, I can not reproduce this.
Therefor, I am closing this as outdated.