Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

Hot answers tagged

6

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 wanted to prevent both sending unnecessary data and creating duplicate contacts. Whenever the data being synced didn't involve a chain of transactions that ...


6

All thanks to the code example link in Eric's answer here's a simplified example of how to offer up a hook (my_new_hook) which takes one argument, $the_argument: CRM_Utils_Hook::singleton()->invoke( 1, $the_argument, $dummy, $dummy, $dummy, $dummy, $dummy, 'my_new_hook'); Then ...


5

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 use a different name.) That's merely a matter of convention, though. The API-wrapper system doesn't impose any constraints on where to put the class or how to ...


5

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 queries to retrieve a CiviCRM entity. Here's an example using the api: function wordpress_civicrm_buildForm($formName, &$form) { $page = civicrm_api3('...


5

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, use hook_civicrm_post to compare the saved record to the stashed one and send the difference. (The preferable way, in my mind) Just use hook_civicrm_post, ...


5

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 install civix and run civix generate:module org.myorg.myextension. Then you can edit myextension.php and paste in that code. However, as that page says - this ...


5

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 :-)


5

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 existing summary content: function demo_civicrm_summary($contactID, &$content, &$contentPlacement) { // Lookup 'created_date' for the specified contact $...


4

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/json'] = array( 'access callback' => true, 'page callback' => 'mymodule_output_my_view_json', 'delivery callback' => 'drupal_json_output', ...


4

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.$. Passing a function straight into jQuery is an alias of calling jQuery(document).ready() (not one that we made up, it's a jQuery thing). The argument your function ...


4

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 Explorer. The foreach loop finds the right result among those returned (even though I specify Custom Field '25' I get results for other fields). function ...


4

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 == 'Group') { print_r($params); die(); } Try creating a group with the Mailing List checked and then creating a group with it not checked to see what it passes. ...


4

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 action: Feel free to give it a whirl on my website - and make a donation if you like it! :-) http://www.breinton.com/book/hipp-abbate


4

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 existing one and implement hook_civicrm_angularModules: function myextension_civicrm_angularModules(&$angularModules){ $angularModules['myModule'] = ...


4

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 civitest_civicrm_buildForm($formName, &$form) { $defaults['register_date'] = date("m/d/Y"); $form->setDefaults($defaults); } This doesn't - $...


4

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: hook_user_login() hook WordPress: wp_login event Joomla: onUserAuthentication event (?) If you wanted to access this from a CiviCRM extension, you'd need to use ...


3

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.


3

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 = false; if (!is_array($contactIDs)) { $contactIDs = array( $contactIDs ); $origValues = $values; $single = true; } then at the very bottom put: ...


3

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 and other ajax-based forms (which don't follow the normal round-trip webpage lifecycle). Instead from your hook you can call CRM_Core_Session::singleton()->...


3

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.status() That page describes the options or how to call them from php too: http://wiki.civicrm.org/confluence/display/CRMDOC/Notifications+and+Confirmations


3

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 upgrade will break someone's custom extension. You can troubleshoot the BAO code. There's certainly something that could be done to make it work (assuming the ...


3

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 return output in this way without writing your own drupal page callback that does something like: function mymodule_output_view($cid) { civicrm_initialize(); $...


3

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 the Net tab and see what comes back when you click your custom tab. My guess is you'll see an HTTP error (a 404, 500, or similar) which will yield helpful ...


3

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 example_civicrm_post($op, $objectName, $objectId, &$objectRef) { if ($objectName == 'Contribution' && $op == 'create') { if (!empty($objectRef->...


3

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 example, the relationship form has this in its post-process function: $this->ajaxResponse['reloadBlocks'] = array('#crm-contactinfo-content'); Which has the ...


3

hook_civicrm_tabs is now deprecated and you should use http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_tabset. Also note: // $url should return in 4.4 and prior an HTML snippet e.g. '<div><p>....'; // in 4.5 and higher this needs to be encoded in json. E.g. json_encode(array('content' => <html form snippet as previously ...


3

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/hook_civicrm_postSave_table_name


3

I ended up adding a small bit of javascript that waits for Angular to build the form, then it disables the checkboxes. Don't know if it's the right way, but it works. CRM.$(function($) { function disable_tracking() { var i = $('#tab-tracking').length; if (i > 0) { $('input[name="url_tracking"]').attr('disabled', true); $('input[...


3

you can use hook_civicrm_postProcess or hook_civicrm_post which ever you need based on your requirement below is the link for more reference http://wiki.civicrm.org/confluence/display/CRMDOC/Hook+Reference


3

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 and implement hook_civicrm_pageRun, something like: function myextension_civicrm_pageRun(&$page){ $pageName = $page->getVar('_name'); if ($pageName ...


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