I'm rather inexperienced in module development, sometimes I have really basic issues: I'd like to grant custom access to user profiles. I think I can do it with the implementation of hook_profile2_access() (profile2 and profile2_og_access submodule use such implementations)

I added the mymodule_profile2_access() to my module but I don't know how/when it would be called?

  • It’ll be called by the entity type manager when access for an entity of that type is requested. But you don’t really need to know that, it just happens, so I wonder if that’s the question you actually want an answer to?
    – Clive
    Commented Jun 5, 2018 at 9:47
  • Well, the question would be why it doesn't seem to work :) if I put this function into custom_profile_access.module (just for testing) it should be working, isn't it? function custom_profile_access_profile2_access($op, $profile = NULL, $account = NULL) { dpm('Hello world'); }
    – StG
    Commented Jun 5, 2018 at 10:18
  • I don't have time to dig deeper right now, but it's called from profile2.module: $access = module_invoke_all('profile2_access', $op, $profile, $account);, in the profile2_access function. That would be a good place to start debugging
    – Clive
    Commented Jun 5, 2018 at 10:36
  • Thanks, I've already found that. '$access' returns with arrays containing true/false values, so I'm not sure it will help me. I will check it again nonetheless.
    – StG
    Commented Jun 5, 2018 at 10:42
  • Have you read the comments? Only grant access if at least one module granted access and no one denied access. So even if your hook implementation returns TRUE, the result will still be access denied if any other module denies access (i.e. returns FALSE from their own implementation of hook_profile2_access)
    – Clive
    Commented Jun 5, 2018 at 10:46

1 Answer 1


Well, it was a typical user error: The implemented mymodule_profile2_access() function is called only for non-admin users and I checked it with administrator. So simple...

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.