0

Our current setup involves a multisite for different parts of our company. We need all sites to share a single user pool for various reason, but each site has slightly different user profile regulations that we need to adhere to. We have different permissions for profile fields on each site, so I need to prevent user profiles being saved if a user isn't on their home site.

I have a field in every profile called "Domain". I intend on pairing this to the current site url to determine if the user is on their home site or not. If not, I need to stop all user_saves from completing. What would be the best way of going about this?

I've found in D6 hook_validate('user') would have done the trick, but there doesn't seem to be anything in D7 that I can use. Would hook_presave work, if I throw an exception?

4
  • What happens when you try it?
    – Clive
    Commented Apr 22, 2014 at 8:46
  • Hi Clive, do you mean hook_validate('user')? If so, nothing, because it's only for nodes - api.drupal.org/api/drupal/modules!node!node.api.php/function/… Commented Apr 22, 2014 at 8:48
  • You mentioned hook_presave(), I wondered what happened when you try it (surreptitiously trying to get you to notice that there's no such hook). hook_entity_presave() is probably what you're looking for, I can't speak to whether or not throwing an exception in an implementation of that hook will cause a problem, I haven't seen it tried before
    – Clive
    Commented Apr 22, 2014 at 8:50
  • Sorry Clive, I meant hook_user_presave(). I'll take a look into hook_entity_presave(). Commented Apr 22, 2014 at 8:52

1 Answer 1

1

You could also try to alter the "user_register_form" and "user_profile_form" and add a custom validation. So in that validation you'll be able to check the domain and set an error if it's wrong.

3
  • Will this also kick in when a module calls user_save()? Commented Apr 22, 2014 at 9:01
  • @BeardedGeek It won't...
    – Clive
    Commented Apr 22, 2014 at 9:09
  • Thought not.. I'll stick to looking at hook_entity_presave() Commented Apr 22, 2014 at 9:15

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.