Hot answers tagged

7 votes

How to create a hook in an extension?

EDIT This answer is now deprecated, you should use @bgm's answer instead, or for an alternative and possibly cleaner approach, try my other answer All thanks to the code example link in Eric's answer ...
artfulrobot's user avatar
  • 3,920
5 votes
Accepted

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

Disclaimer: I'm not an angularjs expert Again this is a bit of a hack, we are intercepting a built-in CiviCRM angular directive and extending to add behaviour. Create a custom extensions or use an ...
Andrei's user avatar
  • 2,321
5 votes

How to create a hook in an extension?

Here is an example of a hook we created for CiviRules: https://lab.civicrm.org/extensions/civirules/blob/master/CRM/Civirules/Utils/HookInvoker.php Hope this helps :-)
ErikH - CiviCooP's user avatar
5 votes

How to create a hook in an extension?

Here is an example using the named parameter syntax: CRM_Utils_Hook::singleton()->invoke( ['pdf', 'pdf_variables', 'receipt'], $pdf, $pdf_variables, $receipt, CRM_Utils_Hook::$_nullObject, ...
bgm's user avatar
  • 3,391
5 votes

Contact Summary Hook Implementation

As already pointed out, the created date is shown on the summary anyway - but since your question is more about using hook_civicrm_summary(), here's an simple example to add the date above the ...
Aidan's user avatar
  • 13.3k
4 votes

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

hook_civicrm_tabs is now deprecated and you should use https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_tabset. Also note: // $url should return in 4.4 and prior an HTML snippet e.g. '<div&...
Hans Rossel's user avatar
4 votes

Setting default date value via civicrm_buildForm hook no longer displays date

I think the date widget have its default value based on the format it is being set. Eg - For mm/dd/yyyy input format set in Administer -> Localization -> Date Formats. This works - function ...
jitendra - fuzion's user avatar
4 votes
Accepted

How to set a default value for a custom field

Used to work, before CiviCRM v5.18 Here's how I've opted to do it. Please do submit alternative answers if there's a better way. Use the civicrm_post hook like this: Note that you need to replace N ...
artfulrobot's user avatar
  • 3,920
4 votes

Is there a hook for on user sign in?

Login is a CMS event, not a CiviCRM event. This means you can access it readily from a CMS plugin/extension/module ... but not from a CiviCRM extension. Drupal: hook_user_login() hook Backdrop: ...
Chris Burgess's user avatar
4 votes
Accepted

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

I'm assuming you have the civicrm_entity module installed. There's an open pull request for this at https://github.com/eileenmcnaughton/civicrm_entity/pull/238 If you're able to test out that patch ...
Demerit's user avatar
  • 22.5k
3 votes

Multiple Entry Custom Values : Find modified ID?

Don't know if this will help, but at least you can try it. :) The custom() hook is called after the db write on a custom table, so when the field is writen, you can't know which was the change, so ...
Albert V's user avatar
  • 472
3 votes

I hacked core and know I shouldn't (How do I use hook_civicrm_batchItems?)

You can create an extension that would export in your format. Here is an example of similar requirement. https://github.com/JMAConsulting/biz.jmaconsulting.greatplains You can use this extension to ...
Pradeep Nayak's user avatar
3 votes
Accepted

Can tokenValue hooks be used in scheduled reminder emails?

I ran into a similar issue of custom tokens not populating for scheduled reminders. The workaround in Brian Shaughnessy's comment on CRM-11153 fixed it for me: early in tokenValues put: $single = ...
davejenx's user avatar
  • 2,365
3 votes

How to display a Drupal view in a CiviCRM tab

For those looking for a no-coding solution to this question, see the Drupal module Views in CiviCRM Contact Page. This module can add Views to a contact's tab.
Jon G - Megaphone Tech's user avatar
3 votes

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

I guess this is not the best way to do it and perhaps someone can point you to a better solution. I'll put it as an answer for readability purposes. Edit Create a custom extensions or use an exiting ...
Andrei's user avatar
  • 2,321
3 votes

Can I disable Notify Activity Assignees for some Activities and/or user levels and leave it on for other Activities/user levels?

The extension mentioned by Peter in the answer is now moved into core and can be used from 4.7.30 version. See https://issues.civicrm.org/jira/browse/CRM-21380 It introduces a new setting which ...
jitendra - fuzion's user avatar
3 votes
Accepted

Where I have to write my hook

"To implement a hook, add a function to the module's main .php file created earlier with civix generate:module" - the developer guide. However, if you've created your own page class, you may not need ...
universalhandle's user avatar
3 votes
Accepted

Extending CiviCRM Advanced search (queryObjects hook)

Ok, I circled back around to this and figured it out. It was staring me right in the face. The following function in CRM/Myextension/BAO/Query/Soundex.php needs changed. There needs to be a hidden ...
David Hayes's user avatar
3 votes

Contact Summary Hook Implementation

The contact created date does show up on Contact Summary page at the bottom of the summary page If you want as a field to show in summary section then i feel you can use civicrm_summary hook but it ...
Pradeep Nayak's user avatar
3 votes

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

You can use civicrm "Smart Group" option for that purpose. Like this: Go to Contact Advanced search, set the relationship type you want as a filter and other filters if you want, like contact type, ...
Hassan Farooq's user avatar
3 votes
Accepted

Add new smarty template to an existing page

I am assuming you want to add some stuff at the bottom of the activity page, correct? First of all, you need to establish if you are adding to a civicrm page or form. You can do a little test with ...
ErikH - CiviCooP's user avatar
3 votes
Accepted

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

CiviCRM keeps track of membership changes in civicrm_membership_log table for all changes to membership attributes like start date, end date, status. But it will pretty difficult for you to guess if ...
Pradeep Nayak's user avatar
3 votes

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

In hook_civicrm_pre, the params passed to your function include qfKey and entryURL — at least sometimes. The entry URL is in a format that's pretty obvious, but it seems like depending on URL ...
Noah Miller's user avatar
  • 1,057
3 votes

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

For folks looking for a no-coding solution to this, you can use the Contact Layout Editor extension to change icons. After installing the extension, go to Administer menu » Customize Data and Screens ...
Jon G - Megaphone Tech's user avatar
3 votes

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

Not as far as I know. You could, however, apply this patch, which introduces generic preInsert and preUpdate hooks to CiviCRM. The copy and demo code for PR explains how you can use these hooks.
Christian Wach's user avatar
3 votes
Accepted

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

For the use case where the email is sent from a logged in user, one could use the function CRM_Core_Session::singleton()->getLoggedInContactID() to get the logged in contact ID. This would fall ...
michaelmcandrew's user avatar
3 votes

Controlling Available Search Kit Actions at a Granular Level

The hook will work to do what you want, but you should inspect the $tasks variable to see what it looks like. The array is keyed by entity type so your code needs to be updated accordingly. But as ...
Coleman's user avatar
  • 18.3k
3 votes

Controlling Available Search Kit Actions at a Granular Level

As of CiviCRM v5.60 this is now doable in the UI! Selecting only certain tasks: Results in limited choices: See https://github.com/civicrm/civicrm-core/pull/25521
Coleman's user avatar
  • 18.3k
3 votes
Accepted

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

The hook_civicrm_alterMailParams(&$params, $context) hook is called twice $context == 'messageTemplate' -> When building the message, at this moment the toEmail is not set $context == '...
Pradeep Nayak's user avatar
3 votes
Accepted

civicrm_post hook not firing upon contact creation

The hooks run in php not javascript, so it won't log anything to the js console. If you want to log, use \Civi::log()->debug('hello'); and then look in the ConfigAndLog directory in the logs there. ...
Demerit's user avatar
  • 22.5k

Only top scored, non community-wiki answers of a minimum length are eligible