0

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 civicrmHooks.php in my "Custom PHP Directory" and tried to simply log something:

<?php

// Implements hook_civicrm_pre

add_filter( 'civicrm_post', 'gutschein_id_custom_callback', 10, 4 );

function gutschein_id_custom_callback( $op, $groupID, $entityID, &$params ) {
  // your code here
  Civi::log()->debug(__FUNCTION__);
}

Civi::dispatcher()->addListener('hook_civicrm_post', "myextension_buildForm", $priority);

function myextension_buildForm($event) {
  Civi::log()->debug(__FUNCTION__);
}
?>

I've tried registering the hook using both methods described in the documentation Hooks in Wordpress Symfony Event Listener. Using the civicrm_custom hook did not change anything.

However, I'm unable to get anything in the CiviCRM log. Is there anything I'm overseeing? Thank you!

5
  • I've partially solved this by creating a small extension. That way I can get the hooks to be invoked. I'm now using the _custom hook. And I get the custom field values in $param. However, I don't get the custom_fields unique id in the param list. Which is what I wanted to use in my key...
    – Flavio C
    Feb 2, 2023 at 20:40
  • Extensions are much preferred - the 'custom php directory' is rarely used now. If I'm understanding you correctly, the id you want is $entityID, not in $params
    – Aidan
    Feb 3, 2023 at 8:57
  • Thank you, yes I did notice that and I was getting it to work with an extension. However I had to look for another solution, because what I was trying to do seems impossible to do. Thank you!
    – Flavio C
    Feb 4, 2023 at 12:45
  • OK - what is it that you're trying to do?
    – Aidan
    Feb 6, 2023 at 9:28
  • I was trying to auto-generate the voucher ID with some kind of unique id. I thought that I might be able to access the id field of the custom field, but it was not available in any of the hooks I was trying.
    – Flavio C
    Feb 7, 2023 at 10:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.