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
37 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']...
user avatar
3 votes
1 answer
78 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 ...
user avatar
  • 2,904
0 votes
0 answers
8 views

Adding/configuring services: config vs container hooks?

If you need to do something with the container, e.g. you want to listen for a particular event, I've seen (and implemented!) a couple of different approaches, and I don't understand the differences. ...
user avatar
  • 3,688
1 vote
1 answer
36 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 ...
user avatar
1 vote
1 answer
15 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 ...
user avatar
  • 1,272
2 votes
1 answer
33 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 ...
user avatar
1 vote
2 answers
28 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 ...
user avatar
  • 1,350
1 vote
0 answers
14 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 ...
user avatar
  • 1,640
0 votes
2 answers
139 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-...
user avatar
2 votes
1 answer
38 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" ...
user avatar
0 votes
1 answer
37 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/...
user avatar
  • 431
1 vote
1 answer
21 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 &...
user avatar
1 vote
1 answer
26 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 ...
user avatar
  • 431
3 votes
1 answer
329 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 ...
user avatar
1 vote
1 answer
11 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 ...
user avatar
  • 91
3 votes
1 answer
19 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 ...
user avatar
  • 31
2 votes
0 answers
27 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: ...
user avatar
3 votes
0 answers
57 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 ...
user avatar
0 votes
0 answers
73 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. ...
user avatar
4 votes
1 answer
38 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 ...
user avatar
1 vote
1 answer
15 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 ...
user avatar
3 votes
2 answers
74 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 ...
user avatar
  • 2,416
1 vote
1 answer
34 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 ...
user avatar
  • 1,640
0 votes
1 answer
30 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 ...
user avatar
  • 357
1 vote
1 answer
34 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 ...
user avatar
2 votes
0 answers
29 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 ...
user avatar
1 vote
1 answer
20 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 ...
user avatar
  • 521
1 vote
0 answers
40 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 ...
user avatar
1 vote
1 answer
47 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, ...
user avatar
  • 1,012
3 votes
1 answer
63 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 ...
user avatar
0 votes
1 answer
40 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 ...
user avatar
  • 197
1 vote
1 answer
72 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 ...
user avatar
0 votes
0 answers
44 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 ...
user avatar
  • 831
3 votes
1 answer
113 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 ...
user avatar
1 vote
1 answer
26 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 ...
user avatar
  • 101
0 votes
1 answer
38 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 = ...
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?
user avatar
  • 146
0 votes
1 answer
183 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 ...
user avatar
0 votes
1 answer
30 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 ...
user avatar
  • 831
1 vote
1 answer
103 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 ...
user avatar
2 votes
1 answer
30 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 ...
user avatar
  • 2,913
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?
user avatar
  • 65
1 vote
2 answers
75 views

Contact Summary Hook Implementation

I am trying to add contact created date in contact summary. I am sure that https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_summary/ helps the requirement. But I'm not getting how to ...
user avatar
  • 65
4 votes
4 answers
265 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 ...
user avatar
  • 3,688
1 vote
2 answers
104 views

How are CiviCRM form names defined (civicrm_validateForm)?

I am attempting to perform form validation on various CiviCRM forms (profile forms and forms within contribution pages) by hooking into hook_civicrm_validateForm. In my php code, I would like to ...
user avatar
  • 167
0 votes
1 answer
25 views

Hook to stop a contact's email from being deleted

We have a new requirement to stop an admin from deleting a contact's email if that email is found in one of our other systems. I am trying to do this through a validateForm hook. I can figure out ...
user avatar
  • 753
0 votes
1 answer
82 views

How do you set the displayed text of a custom field ("view-only")?

I am using Drupal and I have an extensions that I am running this code on. I've seen several threads attempting to help with this. I haven't found any that really make it clear. From what I ...
user avatar
  • 1,146
0 votes
1 answer
56 views

Wordpress hooks – some don't work

I noticed that some hooks are not firing… I have the following three hooks <?php add_filter('civicrm_permission', 'civicrm_permission', 10, 1); function civicrm_permission(&$permissions) { ...
user avatar
0 votes
1 answer
37 views

Customise Contacts Relationships Tab

I want to customise the contacts relationships tab screen to show if the listed contacts (Individuals) belong to a specific group or not. I'm not sure where to start and would appreciate any pointers. ...
user avatar
  • 837
3 votes
1 answer
54 views

Is there a hook for on user sign in?

Is there a good hook for on CiviCRM sign in? [This is to display a message upon login in a cms-independent extension.] Thanks,
user avatar
  • 2,343