Questions tagged [hooks]

Hooks are a powerful way to extend CiviCRM's functionality, incorporate additional business logic, and even integrate CiviCRM with external systems. The way they work is, that at key points in processing CiviCRM checks if custom code is "hooked in", and runs any valid code it finds.

Filter by
Sorted by
Tagged with
1 vote
1 answer
22 views

How to generate field values on save

I would like to set the value of the case subject field automatically on saving. The value is made up of the values of the client name and a custom field. Is the postProcess or the post hook the ...
2 votes
1 answer
21 views

Populate a Contribution form custom field from a URL parameter

I know I can do it using civicrm_buildForm but I don't know: How to get the custom field How to set the value to this field
1 vote
1 answer
50 views

How am I meant to use $mask in hook_civicrm_links?

I don't really understand what the point of the $mask variable that is passed to hook_civicrm_links is. Can anyone explain it to me? PS I understand how to use the other variables and I might not need ...
1 vote
1 answer
13 views

CDNTaxReceipts extend $pdf_variables[]

CDNTaxReceipts is a Tax Receipts extension for CiviCRM. This extension is a way to generate pdf including recipient's personal data. Those Data are listed in an array $pdf_variables declared in ...
3 votes
1 answer
75 views

What is deleting my Tag?

I've run into this twice this month and scratching my head. Read this image upside down: We hit post create Address hook -> my regex extension creates a Tag - all good; happy dance; then something in ...
0 votes
1 answer
13 views

How can I utilize Drupal hooks for altering and validating forms in place of CiviCRM hooks?

My website is built on Drupal, and I prefer using Drupal hooks over CiviCRM hooks for modifying and validating forms, as I find Drupal modules easier to create and their hooks more user-friendly. ...
1 vote
1 answer
47 views

How to get $activity_id or $case_id variables in HOOKs when cron job execute in Joomla?

How to get $activity_id or $case_id variables in HOOKs when cron job execute in Joomla? I have 2 functions in HOOK for CiviCase function joomla_civicrm_tokens(&$tokens) function ...
3 votes
1 answer
156 views

Implementing tokens and tokenValues hooks for Event custom field

I'm trying to implement a hook for inserting Event custom fields into Scheduled reminders; however, I'm not a developer so I'm really not sure what the code needs to look like. The custom field is ...
4 votes
2 answers
76 views

Can't change help_post text in Price Set using the civicrm_buildAmount hook

There are several fields I expect to be able to change in the buildAmount hook that just won't change for me. One example: function myext_civicrm_buildAmount($pageType, &$form, &$amount) { $...
2 votes
1 answer
92 views

Triggering hooks upon quick edits

We would like to implement a 'computed' custom field. Meaning a custom field A depends on the values of other custom fields B, C and D. We need this to work when editing the data via the CiviCRM admin ...
0 votes
1 answer
28 views

civicrm_api3('Contact', 'create', in hook_civicrm_pre?

Getting a loop and consequently out of memory while executing the code: function hook_civicrm_pre($op, $objectName, $id, &$params){ if ('Individual' === $objectName && 'edit' === $...
1 vote
1 answer
41 views

civicrm_post hook not firing upon contact creation

I am writing a custom plugin for wordpress that stores contact data when a new individual is created in CiviCRM. I wrote a test function to see if the 'civicrm_post' hook fires when a new individual ...
4 votes
3 answers
317 views

Controlling Available Search Kit Actions at a Granular Level

Some permissions allow actions that may not be desirable to have as a search action that can be done en masse. e.g. I may want contacts to merge records but not delete records en masse on a search ...
0 votes
0 answers
28 views

unable to get hook_civicrm_post and _custom to work

I'm using CiviCRM 5.57.3 to implement some voucher management functionality See this question. I'm now trying to get a hook working, to set my voucher ID in the custom field. I've create a file ...
0 votes
1 answer
38 views

Why does civicrm_postProcess hook does not pass certain parameters?

Only the "$formName" variable is getting supplied to the hook callback. Why are the rest of the variables listed in the documentation not getting supplied? add_action('civicrm_postProcess', '...
1 vote
1 answer
52 views

Changes in hook__civicrm_alterMailParams not respected anymore when sending mails to individual contacts

In our development environment I redirect mails following some specific rules. I am quite sure that I achieved that in the past with hook__civicrm_alterMailParams where I changed the $params['toEmail']...
9 votes
6 answers
455 views

How to change mailing form and set the default value for url_tracking to false?

Is it possible to alter the mailing form? I want to set the default value for url_tracking to false. Usually I would write a hook_civicrm_buildForm and set a custom default value but this hook is not ...
4 votes
4 answers
327 views

How to create a hook in an extension?

I want to give others the chance to do something when certain events happen in my extension. So to be clear: I'm not wanting to use existing hooks in my extension, I'm wanting to create a new hook ...
1 vote
1 answer
36 views

custom fields in hook_civicrm_pre' $params have an extra "_-1" suffix

On my latest Civi 5.37.2 the params array passed to hook_civicrm_pre looks like: Array ( [hidden_custom] => 1 [hidden_custom_group_count] => Array ( [] => 1 ...
5 votes
2 answers
268 views

Add Donations to Event Registration Form

I'm trying to give people an option to add donations to special projects when they register for a particular event. We could just point folks to the contributions pages, but it would be more effective/...
2 votes
1 answer
45 views

Is it possible to create a token in hook_civicrm_tokenValues that retrieves the name of the creator of a non-mass-mailing?

One of our staff team has recently requested a new token be added to civi mailings that allows the name of the sender of the email to be automatically added (for use in the signature at the foot of ...
0 votes
1 answer
36 views

How to call my post_provision_install hook after CiviCRM installed?

I want to automate the removal of households from CiviCRM, right after it has been installed via Aegir on Drupal 7. I implemented my post_provision_install hook, but it runs before the same hook of ...
1 vote
2 answers
40 views

hook_civicrm_alterCalculatedMembershipStatus

It seems that hook_civicrm_alterCalculatedMembershipStatus is the right place for adding various actions based on Membership change. It looks like there is some issue with $membership array from the ...
1 vote
0 answers
25 views

'view' op in pre and post hooks: actually used anywhere?

Working on a PR to add pre and post hooks for the UFGroup entity, I looked for existing examples of entities that invoke these hooks with the 'view' $op (documented in the 'parameters' section for ...
0 votes
2 answers
155 views

Use complete address and full county name in mailings

Working on a mailing that includes contacts full address details. And I'm encountering an issue for UK addresses where the county is abbreviated in the same way US states are. I've never seen such 3-...
2 votes
1 answer
52 views

How to provide custom token for subscription related automated messages?

I'm trying to privide a token for mailing related automated messages. I followed the instructions about hook_civicrm_tokens and hook_civicrm_tokenValues but it does only work for "CiviMail" ...
0 votes
1 answer
80 views

Adding a field to the Create Activity Form

I'd like to change the form that opens when adding an Activity to a Case (depending on activity type). Specifically, I'd like to add a field. I tried finding the fields I want to change in sites/all/...
1 vote
1 answer
38 views

Is there a hook that will be called before each database read?

I'm trying to get a little more familiar with writing extensions. I am still struggling with finding the correct / most specific hook function for my patches regularly. As a specific example, I am ...
1 vote
1 answer
29 views

Hook postProcess doesn't work with message templates form

I'm trying to add a couple of fields to the message templates ("CRM_Admin_Form_MessageTemplates") in a custom extension. I use the "buildForm", "validateForm" and the &...
3 votes
1 answer
404 views

Why am I getting a warning about hook_civicrm when Civi's cron runs?

On Drupal 7.73 with CiviCRM 5.29.1. Every time the CiviCRM cron runs, I get the following warnings in the Drupal watchdog log. Each is a separate entry. hook_civicrm_alter_drupal_entities should be ...
2 votes
3 answers
168 views

How to customise the activities tab listing

I used to hack the Activities BAO to change the search results to make the subject line something more useful; i.e. extract other data from particular activity types and auto-create a summary in place ...
1 vote
1 answer
25 views

How can i check current user is administer in civicrm hook?

I am using the hook_civicrm_tabset for rename the tab name. Tab rename code is working properly. But i want to add condition if user is admin then rename the tab name. How can i check user is admin in ...
1 vote
2 answers
362 views

How do I add new tab to the Contact Summary Page?

I create a new plugin and I try to use hook for adding extra tab in the contents, my question is how to get $contactID? add_action('civicrm_tabs', ' civitest_civicrm_tabs'); function ...
3 votes
1 answer
26 views

membershipTypeValues hook not updating membership price

On my civicrm contribution page I have a field that I want to use to calculate the membership price. Currently Im trying to use the membershipTypeValues hook to edit the price after the contribution ...
2 votes
0 answers
31 views

How to use a GROUP_BY / HAVING in extended Advanced Contact Search query?

Based on this solution, I'm trying to add a custom pan in advanced search in order to filter by Line Item Total Sum. The context I successfully manage to filter by Line Item Total with these fields: ...
3 votes
0 answers
88 views

Building the equivalent of a webhook for certain CiviCRM events

I posted this in the Mattermost Town Square, but was encouraged to post the question here also: Good afternoon. I'm wondering if CiviCRM can produce a "changes stream" or fire off a webhook ...
0 votes
0 answers
109 views

Creating membership with civicrm_api3, inherited membership

I'm trying to create inherited memberships in the civicrm_post hook. I feel like there is something wrong with the api itself. The API doesn't even recognize my only membership id in the database. ...
4 votes
1 answer
56 views

Is there a hook to impact custom data before it's saved?

I feel like I've hit this issue before and found a solution, but I'm drawing a blank right now. I need to be able to compare the value of a custom data field before it's saved in order to ...
4 votes
3 answers
801 views

How to set a default value for a custom field

EDIT: this is NOT working, at least in CiviCRM 5.24.2 EDIT: this is done automatically by CiviCRM from 5.18+ I have a custom fieldset on Contributions that uses an option list. The option list has a ...
1 vote
1 answer
22 views

Control duplicate entries in Hook Post

I'm in need of inserting a control query into a hook post to retrieve if there is duplicate data. I am using a php query but the only reaction I have is that it continues to compute forever, is it ...
3 votes
2 answers
89 views

How can I customize the default gear icon on a custom tab set?

Now that there are icons on all the tab sets (awesome, btw) - I'd like to change the standard gear icon that appears on any custom contact field sets that are set to display as a tab. I didn't see ...
1 vote
1 answer
46 views

Using hook_civicrm_tabset; why doesn't my tab focus when linked to via url?

I've added a tab adjacent to the event "Info and Settings" configuration tab, using hook_civicrm_tabset(), but when I link to the URL for that tab, the "Info and Settings" tab is displayed. This ...
1 vote
1 answer
45 views

how can I create an hook when external id change

I would to ask you , on how can create an event (programatically) when I change the external ID in contact form, how can I t make some kind of process like validation in another module or service I ...
2 votes
0 answers
40 views

Errors not showing against custom fields using hook validateForm()

Using this code if ($fields["custom_111_79"] == 0) $errors["custom_111_79"] = "Please enter number of physio sessions"; The evaluation is done correctly, but the error message does not appear ...
1 vote
1 answer
44 views

Get Contact id from Relationship to use in a Hook [duplicate]

I want to display Contact B ID of a relationship for the current contact. I am building a hook and this is my code so far. if ( $formName == 'CRM_Contactlayout_Form_Inline_ProfileBlock') { if ...
1 vote
0 answers
62 views

Stripe Webhooks on a multisite?

I've just updated a multi-site with the latest Stripe extension and I get the message to update the webhooks. Did this on another site earlier I was able to just follow the links and it updated as it ...
1 vote
1 answer
50 views

Ways for an extension to determine how (by which form/screen/API) a Contribution was created?

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, ...
2 votes
3 answers
244 views

post hook edit entity

We have a post hook that sends some data to an external api when a participant is created or edited. function kavo_civicrm_post($op, $objectName, $objectId, &$objectRef) { if (($op == 'create' |...
1 vote
2 answers
135 views

How to clear hook cache

When I am changing a query or logic in my hook, I have to reinstall the entire module so then only the updated logic / code works in civicrm. Is there a settings to clear the cache or something I ...
0 votes
1 answer
63 views

How to set a permission using drupal ACL?

I am developing an extension. I want to provide permissions using drupal. I am using following hook for creating a permission hook_civicrm_permission(&$permissions); But, how to do that (means ...