Is there a good hook for on CiviCRM sign in?

[This is to display a message upon login in a cms-independent extension.]

Thanks,

Login is a CMS event, not a CiviCRM event. This means you can access it readily from a CMS plugin/extension/module ... but not from a CiviCRM extension.

If you wanted to access this from a CiviCRM extension, you'd need to use some event which fires at the time of login. You might be able to identify one using the contrib.showallthehooks extension to reveal which hooks get fired at the point of login. Might need to check it was going to fire for each of the CMS platforms, since behaviour could vary.

  • You can also use CIVICRM_UF to include a cms-specific .inc file from your main file, just you'd have to write the 4 files, but they'd be minimal and could all call the same function ultimately. E.g. include "onlogin_" . CIVICRM_UF . ".inc"; – Demerit Nov 8 '17 at 14:22
  • Demerit - interesting idea, but this wouldn't register those implementations with the CMS would it? (If CiviCRM didn't register civicrm_user_login() then your extension could define same to have it called in Drupal, but it might not be loaded in time, and you'd be risking a collision if CiviCRM or another extension ever incorporating their own definition of the same.) – Chris Burgess Nov 8 '17 at 20:28
  • Very interesting idea - this is only to displaythe number of unread SMS messages, so ordering isn't so important. – JohnFF Nov 8 '17 at 22:57
  • The extension main file doesn't need to be all civi hook functions, it can have other code, so it depends when php/civi itself does a "require" on your main extension file, but I imagine if you just put the "include" or "require" at the top of your main extension file that would do it. My suggestion was mostly taken from what I've seen the hook system in civi itself do. See e.g. the CRM/Utils/Hook subfolder, where it has separate implementations for each CMS, and which one gets used is ultimately based on CIVICRM_UF. – Demerit Nov 9 '17 at 0:32
  • Another idea is just display that SMS count on the dashboard, or whatever page is defined as their home page, so it doesn't depend on login, just whatever is their home page. Although if their home page isn't a civi page, then you might not be able to use a civi hook to do that, but then how are you doing the outputting in a generic way? – Demerit Nov 9 '17 at 0:41

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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