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 ...
Jan's user avatar
  • 145
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
marcelo2605's user avatar
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 ...
Pierre's user avatar
  • 15
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 ...
Duf59's user avatar
  • 121
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' === $...
yurg's user avatar
  • 2,005
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 ...
Atiksh Gupta's user avatar
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. ...
nonono1234's user avatar
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 ...
Flavio C's user avatar
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', '...
dsmith63's user avatar
  • 419
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']...
Tobias Krause's user avatar
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 ...
Andy Burns's user avatar
  • 3,681
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 ...
Vadim Kozhevnikov's user avatar
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 ...
nielo's user avatar
  • 1,304
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 ...
William Gordon's user avatar
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 ...
yurg's user avatar
  • 2,005
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 ...
TwoMice's user avatar
  • 1,814
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-...
dmgeurts's user avatar
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" ...
Philipp Michael's user avatar
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/...
emma's user avatar
  • 493
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 &...
Jan-Derek Vos's user avatar
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 ...
emma's user avatar
  • 493
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 ...
The Amateur's user avatar
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 ...
jagjeet's user avatar
  • 101
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 ...
Jeremy's user avatar
  • 31
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: ...
Bastien Ho's user avatar
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 ...
phillipadsmith's user avatar
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. ...
Kurt Leadley's user avatar
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 ...
lcdservices's user avatar
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 ...
Ictadmin's user avatar
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 ...
RayWright's user avatar
  • 2,488
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 ...
TwoMice's user avatar
  • 1,814
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 ...
Doka's user avatar
  • 397
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 ...
Aneury Perez's user avatar
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 ...
Simon Walden's user avatar
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 ...
Moe's user avatar
  • 521
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 ...
Rose Lanigan's user avatar
  • 1,020
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, ...
Noah Miller's user avatar
  • 1,057
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 ...
KarinG - Semper IT's user avatar
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 ...
deepak's user avatar
  • 197
1 vote
1 answer
95 views

Validation radio custom fields on civicrm_validateForm hook does not work

I have a custom field on contact in radio type format, not required field. I'd like to set up custom error on this field by using hook_civicrm_validateForm when the field is null. // hook in ...
Scardinius's user avatar
0 votes
0 answers
58 views

How to alter a query in hook_civicrm_pageRun based on a custom filter provided?

I want to alter the query run in the hook_pageRun(&$page) under Manage Events Page to alter the (event list) results shown here. I can alter the rows from hook_civicrm_pageRun , but I want to ...
harshal's user avatar
  • 841
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 ...
FCRCadmin's user avatar
1 vote
1 answer
40 views

Hook pre/post in pledge changed status

On 5.6.0 After create a pledge. If is created a new contribution that change the status of the pledge from "Pending" to "Completed" is not incoming in any hook_civicrm_post or hook_civicrm_pre with ...
rubofvil's user avatar
  • 101
0 votes
1 answer
41 views

I am trying to insert custom tab into Activity tab but it is not working

I am creating new extension. I am adding a new custom field into Activity tab but it's not working //Creating a custom group for survey function custom_group_create_survey(){ $survey_custom_group = ...
Dipak Giri's user avatar
1 vote
2 answers
30 views

Is there any information that tells the last action of membership record (edit or renewal)?

I'm going to write a hook to distinguish a saved membership record, how do I know the last action of saved membership record is edit or renewal?
pnbps's user avatar
  • 146
0 votes
1 answer
230 views

Adding a column to search results

i try to add a custom column to the search results of "find contact". I use the hook "searchColumns", i can easily add a column with: $headers['summary'] = array('name' => 'Summary'); , but when ...
Jan-Derek Vos's user avatar
0 votes
1 answer
35 views

How to fetch Profile gid from hook_civicrm_post included in a Contribution Page?

I am using profile object inside function hook_civicrm_post($op, $objectName, $objectId, &$objectRef){ } How can I fetch the Profile gid from the above variables? or is there any way to ...
harshal's user avatar
  • 841
1 vote
1 answer
132 views

Add new smarty template to an existing page

I want to add a new template part to the activity edit & view page, I have been trying number of hooks to do it but could not figure out which one best to use. I am trying to do something similar ...
Arun Singh's user avatar
2 votes
1 answer
34 views

Which table is used for hook_civicrm_triggerInfo?

I have a rebuild trigger action that is failing. It is trying to create a trigger on civicrm_contributiion_recur. Clearly it has 2 i's and shouldn't. There is or was a trigger on the table without ...
Paul-Tahoe's user avatar
  • 2,965
1 vote
2 answers
30 views

How to automatically remove a contact from specific group, if end date is added to specific relationship

If end date is added to relationship,the contact should be automatically removed from the specific group. How this can be accomplished?Any suggestions?
preeti's user avatar
  • 65