1

I have a D7 installation with about 2k "project" nodes, which have a multi-entry field "team members" used to control view and edit access.

So far, I have my (pretty complex) logic inside node_access, and it works fine. But views (e.g. a "new projects" feed) don't respect node_access. The mymod_node_access hook is called (I see it with dpm()), but the nodes still appear in the view result.

Obviously I could simply hide the elements using a view field template, but that breaks the paging system (e.g. user selects "10 projects per page", but sees only four).

How can I make the Views module respect node_access as a filter?

  • hook_node_access only gets invoked for individual nodes. What you could do, that will also repsect the pagination is add a view filter to filter only projects where the current user is a member of (if that's what you want to achieve) You'll probably need to do it with a contextual filter. – Alari Truuts Apr 14 '16 at 14:03
  • Problem is that it's not just the "team member" field that controls access, there are also rules based on role membership and other factors, so it isn't really possible to use ordinary views filters - and I wouldn't like to duplicate the logic in node_access to avoid a code split or risk a mismatch between the filter and node_access. – Skynet Apr 14 '16 at 14:16
  • @Skynet Would you be interested in suggestion for a possible alterrnative (a module you may not be aware of) that you could use to replace your entire "access" implementation (your special field, and the node access module)? PS: is this D7 or D8? – Pierre.Vriens Apr 14 '16 at 16:27
  • Why not? As long as I can replace node_access AND drupal filters with one solution, I'm fine. Btw, I'm on D7. – Skynet Apr 14 '16 at 16:53
0

If you are willing to give it a try to "replace node_access AND drupal filters with one solution" (as per one of your comments), then have a look at the Group module (commonly perceived as an alternative for Organic Groups).

Group allows for creating arbitrary collections of your content and users on your site, and grant access control permissions on those collections. It is available as of D7, and has a D8 version also. The Group module creates groups as entities, making them fully fieldable, extensible and exportable. Which also makes it integrate very well (out of the box) with commonly used modules such as Rules, Views, etc.

Some more questions you may want to look at for more details:

Resources

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.