I'm creating an extension. It should:
- intervene when a Contribution is created, and make some changes to the data
- only intervene if the Contribution was created via a public-facing Contribution Page, or via the Import Contributions UI
- not intervene if the contribution was created through the back-office UI, batch data entry, a public-facing event registration form, or any other method.
My plan was to use hook_civicrm_pre
or hook_civicrm_post
to intercept the Contribution at the time of its creation... but I need to know which context the Contribution is being created/updated in, so I can make sure I'm only modifying the data in the desired contexts.
How can I determine, within my hook implementations, what context the Contribution is being created in?
(Bonus points for determining contexts other than the ones I listed above. For example, CLI or REST API.)