I'm new to Civicrm PHP and extension development so I'm sorry if this is a dumb question. ^-^

I'm making an extension that creates a new custom field group, the custom field group is meant to replicate the fields of a contribution (so it has payment method, amount, currency type, ETC).

The problem is the financial type id field, unlike payment method there isn't an option group that I can link the custom field to.

I've made a work around by creating an option group, updating the values inside to copy any changes made to the financial type table, while it's somewhat functional it's messy, breaks my site sometimes and has caused me hours of work fixing it (I've had to make checks in install, uninstall, enable, disable, postCommit hooks)

Is there a way I can add it to cause less bugs/errors like the contribution form, or should I just stick with my current work around and optimize it?

Help would be appreciated! I've been working on this extension for nearly a month atp haha ^-^

1 Answer 1


Handling install, uninstall, enable, disable is exactly what hook_civicrm_managed() is for! While this is an admittedly strange use for it and I have to wonder whether reproducing contributions using custom fields is really the best way to approach whatever problem your extension is trying to solve... that aside, it can be done!

  1. Upgrade your copy of civix to the latest version.
  2. Find the id of the option group you've already created to represent financial types (let's say it's 99).
  3. From within your extension's directory, run the command civix export OptionGroup 99
  4. This will generate a new .mgd.php file in your extension's managed directory.
  5. The file consists of 1 declaration of the optionGroup, plus a declaration for each option value. Leave the first one, and you'll convert the option values to a foreach loop:
  6. In the .mdg.php file, you can call the api to fetch all financial types, then loop through them to add to the return value.
  • Ohh I see, I've tried to use the manage hook and didn't know you could do api calls in it, can you use api4 or is it strictly api3? for clarification I'm making an extension that adds a new activity type, so that it can be mapped onto a ninja form and when a user fills in the form an activity is generated, later when that activity is marked completed it creates a new contribution using the user's field's input on the activity ^-^.
    – BellaDoll
    Commented Dec 27, 2023 at 1:02
  • Yes you can (and should) use APIv4. That is the format civix export will generate for you.
    – Coleman
    Commented Dec 27, 2023 at 13:38
  • Why not have the ninja form directly create a contribution & set the status as Pending?
    – Coleman
    Commented Dec 27, 2023 at 13:40
  • Thank you for the help! it worked. As for ninja forms creating the contribution out right, to my knowledge the ninjaforms add-on for civicrm only allows for the creation/modification of contacts and activities, not other entities like cases or contributions. However there's an additional reason as to why i need the activity and not just the contribution that I cannot state , but thank you again ! ^-^
    – BellaDoll
    Commented Dec 28, 2023 at 1:17
  • You're welcome!
    – Coleman
    Commented Dec 28, 2023 at 20:53

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.