Short Version:

What would you say is the best way to filter how nodes appear (in a binary sense: published vs. hidden) to users based off of a dynamic value? This solution is beyond the scope of typical modules like Permissions, Views, or Content Access.

Long Version:

My application calls for having select nodes display to select users based off of values changed over time. For instance, lets say a user wants access a node but both the users and the nodes change their location (daily). When a customer views the site (or any page) I want them to only be able to see nodes in their specified range. Because of this the basic Permission and Views and other stock Drupal modules seem to be ineffective. It seems like it would be a bad way to use the Permission system because their are so many variables in the user / node relationship. I can't unpublish nodes because they need to remain active to other users, processes, etc. Even a dynamic Views filter with custom php code for my distance measurement would be ineffective because then nodes would still be accessible by directly inputting the URL.

Thus far, I am planning on using hook_node_load() to perform my calculations - determining the user and node relationship - and then only return nodes that are applicable. This should prevent direct URL access to unavailable nodes, keep active nodes that exist but don't match the criteria, and by default control


You say that you do not want users to be able to enter node URLs directly. To me this suggests you do need to use permissions, as it is the only way tou can guarantee your node won't be accessed.

The reason is that you never know which parts of Drupal might be displaying your node. For instance you could manually insert a drupal_goto in hook_boot to provide your own custom permission handling, testing the URL for the node id - however the node would still be accessible via Views. The great thing with Drupal is that all sorts of modules can use your data in all sorts of ways - however this means you have to present your data (in that case, your permissions) in a way other modules will understand.

You say that your permissions are distance-based. This means you cannot use Role-based permissions, since you would end up having one role per user. What you could use however is the ACL module - this provides an API allowing you to define per-user/node permissions.

You would then need to implement hook_node_update/hook_user_update to re-calculate the permissions and change the ACL for that node/user when the node/user is changed.

| improve this answer | |
  • Thats a pretty thoughtful response, thanks. I have looked at the ACL module before. Do you know of any good documentation, guides, or examples for implementing it? – kevinaskevin Apr 8 '13 at 17:16
  • I'm afraid not - though you can check drupalcontrib.org/api/drupal/contributions%21acl%21acl.module/7 as a starting point. Basic concept: You can create any number of ACLs. Each ACL can have any number of users, and be associated with any number of nodes. For each node you can define the view/update/delete permission that will apply to the users of that ACL. You should try to read about/understand Drupal permission system. – Alice Heaton Apr 9 '13 at 9:12
  • I get what your saying but I'm leaning against making user lists. I'd rather execute the calculation at the time the module is viewed. Other wise I would have to have update this list constantly, as you mention at the time of hook_node_update / hook_user_update. Which I get but that would mean I would have to do that work for every node and user no matter how outdated and not just the users that are on the site at that given time. – kevinaskevin Apr 9 '13 at 16:10
  • Also you could have a look at the AUL module drupal.org/project/aul – milkovsky May 11 '14 at 18:14

node_access_example.module (link) would appear to be the best response to the issue of custom filtering of nodes through the node API. It and a few other comments (1) (2) describe these as being the key hooks in accomplishing this task:

| improve this answer | |

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.