CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Determine how hook was called? Determine Role?
Pages: [1]

Author Topic: Determine how hook was called? Determine Role?  (Read 980 times)

ijames

  • Guest
Determine how hook was called? Determine Role?
March 17, 2010, 08:29:47 am
Hi,

I'm working on using a hook_civicrm_pre and _post and I'm wondering how I can tease out the way it was called. 

If I'm correct, it could be a:

  • logged in user in one of many access permission combinations
  • non logged in visitor
  • SOAP/REST call (which would also be for cron hook right?)

Is there a way to determine which of these situations I'm in from within the hook itself?

Thanks a lot!

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Determine how hook was called? Determine Role?
March 17, 2010, 09:42:41 am

you can check about the user / anon by using the drupal global $user

you can check the context by checking $_GET['q'] in drupal, gives you an idea of how / where the hook was invoked from

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

ijames

  • Guest
Re: Determine how hook was called? Determine Role?
March 17, 2010, 11:56:41 pm
Thanks! 

Ok, I can see the difference with the q parameter but I'm not seeing the $user...

But now, I'm also wondering how to use PRE to add information into a custom contribution field.  I tried to do an add, but, that went recursive, big surprise...





Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Determine how hook was called? Determine Role?
March 18, 2010, 06:47:19 am

$user is a PHP global variable, u'll need to use:

global $user;
// use and test $user here

For an already exisiting custom contribution field, you can modify the value. the system prevents adding arbitrary custom fields

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Determine how hook was called? Determine Role?

This forum was archived on 2017-11-26.