1

I'm trying to figure out the best way to limit access to a view based on a boolean field in the user profile. If the user checks the box for that field they will have access to the view, otherwise not.

I could use views_php for the access control of the view. Would that prevent the view from getting cached with views caching?

Or should I use a hook_form_alter() to check for the value each time the profile is saved and then add or remove from a special role?

1

1 Answer 1

1

I do this on my site using Rules. I use the Data comparison condition on profile save and then add or remove the role as necessary. If you do decide to use the Rules module, make sure to add a NOT Data comparison as well to make sure the Rule doesn't get called multiple times (I had problems with this).

Example:

  • Event: After updating an existing user account
  • Condition: NOT Data Comparison: account-unchanged:field_mycheckbox is Yes
  • Condition: Data Comparison: account:field_mycheckbox is Yes
  • Action: Add a role

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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