2

I have two content types, Location and Event. The Location has a user reference field containing the owner of the Location. The Event type has a node reference field containing the Location node it belongs to. Now I want the owners to be able to create Events only for their Locations based on this reference field.

Currently I "solved" this by having a Views reference in the Event type that only shows Locations where the author is "Drupal"-owner of the nodes. But this has two downsides:

  1. Administrators get an empty Views reference and thus can't save Events
  2. I have to change the author of the Location node instead of using the user reference field I added

So, is there a way to solve this?

0

I would create a custom module that uses Entity Field Queries to do the following:

  1. First, use EFQ to select nodes of type "location" where "user" matches the "user" specified in the selected "event" AND also the "location" value matches the "location" specified in your event. This has essentially the same effect as the Views solution you've worked out, I believe.
  2. The advantage over Views here is that now you can node_load() the nodes you find or you can execute more complex logic if there are no matches (i.e. if the user should not have permissions).
  3. Use hook_node_grans() or hook_permission as needed.
0

Check out the http://drupal.org/project/nodeaccess_userreference and http://drupal.org/project/nodeaccess_nodereference modules. Extremely flexible for creating entityreference based view/update/delete permissions.

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.