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 ...
user avatar
  • 3,678
6 votes

Is there a CiviCRM hook or other method which can be used to push data updates to other systems?

In having to do this with Salesforce and CiviCRM a number operations included the creation of a new contact being initiated on one end, which then had to be replicated on the other. In this case we ...
user avatar
6 votes
Accepted

Add Donations to Event Registration Form

Simply set up an additional line item for a donation in a Price Set. This is how I do it... the Price Set definition: And then how the 'Optional Donation' is defined: And a preview of this in ...
user avatar
5 votes
Accepted

Where to put api wrapper class in an extension

The example in the wiki was problematic. If you look at the wrappers included with core, they're never placed under the api/v3 folder -- they're always under CRM/Utils/API. (I've updated the wiki to ...
user avatar
  • 5,564
5 votes
Accepted

Trying to write a hook to add contribution page name to Main.tpl I'm super close

Looks like you are trying to access a variable that's been assigned to the template, not the object. I'd say just access the variable $form->_id directly. Also, I suggest you do not use raw sql ...
user avatar
  • 16.1k
5 votes

Is there a CiviCRM hook or other method which can be used to push data updates to other systems?

Unfortunately, there's no good one-step approach that I know of. Two options: Use hook_civicrm_pre to trigger fetching the data from the database and stashing it somewhere prior to the change. Then,...
user avatar
  • 7,337
5 votes
Accepted

Using hooks -- simple please

To use a hook, you can: Write a CiviCRM extension. This is the preferred method. Write a Drupal module. Write a Joomla or Wordpress plugin. The easiest way to write a CiviCRM extension is to ...
user avatar
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 ...
user avatar
  • 2,301
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 :-)
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, ...
user avatar
  • 2,986
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 ...
user avatar
  • 10.9k
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&...
user avatar
4 votes

How to display a Drupal view in a CiviCRM tab

Extrapolating on Coleman's answer, you can get the json output required by creating a new Drupal page with hook_menu. Here is the full code: function mymodule_menu() { $items['civicrm-videos/%user/...
user avatar
  • 141
4 votes

Hook to change the Success message after CiviCRM submits a form?

Xavier's answer is generally right but because you are in the context of a form I advise don't use the function CRM_Utils_System::redirect because that is a rather blunt instrument, and breaks pop-ups ...
user avatar
  • 16.1k
4 votes
Accepted

How to insert Javascript into an inline form edit via an extension?

cj(function ($) {}) has an implicit document.ready. To unpack that dense few characters of code: cj is the deprecated alias of CiviCRM's copy of jQuery. In 4.5 and above use the new one: CRM.$. ...
user avatar
  • 16.1k
4 votes

How do I use the API to access protected custom data in a hook?

I followed @xavier's answer, but I'm posting what I did in case it's useful to others. See the code below. The '25' is a magic number for this Custom Field, and can be found using the CiviCRM API ...
user avatar
  • 997
4 votes

How can I make every new Group a type Mailing List?

Use hook_civicrm_pre to modify the group-to-be prior to saving in the database. Experiment a little with your hook function, adding the debug lines: if ($op == 'create' && $objectName == '...
user avatar
  • 7,337
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 ...
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 ...
user avatar
  • 3,678
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: ...
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 ...
user avatar
  • 17.6k
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.
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 = ...
user avatar
  • 2,320
3 votes
Accepted

Hook to change the Success message after CiviCRM submits a form?

You can redirect using the CRM_Utils_System::redirect($urlyouwant) and use CRM_Utils_System::url to build the url itself. you can as well display pop up messages using CRM.alert() or CRM....
user avatar
  • 10.1k
3 votes

Custom code that sets custom field value stopped working in 4.6

I don't believe that the document you referenced is current best practice - it should probably be rewritten! Using the BAO rather than the API to set values greatly increases the chance that an ...
user avatar
3 votes

How to display a Drupal view in a CiviCRM tab

Generally when CiviCRM uses ajax to fetch content it is not expecting to get raw html back from the server. What it expects is a structured json array. I don't know of a way to easily get Views to ...
user avatar
  • 16.1k
3 votes

How to display a Drupal view in a CiviCRM tab

If you're receiving that error, that probably means an AJAX call is failing. Check out these troubleshooting tips - but more importantly, in your Developer Tools tab (F12 in Firefox/Chrome), check ...
user avatar
3 votes

How do we preprocess CSV columns when using CiviCRM builtin import functionality?

One possibility could be importing the data as it is (maybe using a temporary field for that column) and use hook_civicrm_post() to manipulate the contribution just after creation: function ...
user avatar
  • 181
3 votes
Accepted

Can I update/requery a custom field that got changed via another field on the same page?

The contact summary screen is divided into different panes, and they are each refreshed separately. If a popup form needs to refresh one or more panes, it can specify them by jQuery selector. For ...
user avatar
  • 16.1k
3 votes
Accepted

Is the postSave hook a supported hook?

Reading the code and that issue, the hook exists and someone just forgot to add it to the wiki. Here, I've just added it: http://wiki.civicrm.org/confluence/display/CRMDOC/...
user avatar
  • 16.1k

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