Extending CiviCRM (without hacking core)
Facilitated by CiviCRM Core Team
This session is designed for developers who want exposure to a variety of techniques for extending, and customizing CiviCRM - and integrating it with other applications WITHOUT taking on the risks of modifying core code.
- CiviCRM hooks - overview and examples
- CiviCRM APIs - overview and examples
- Case Study / code walkthrough - Building a school after-care registration module on top of CiviCRM using hooks
Any system does 70-80% of what you want. Challenge is how to allow developers to get the rest of what they need w/o changing core codebase.
Explanation of hooks - a great idea CiviCRM picked up from Drupal. - hook is an open ended question.... I'm doing XYZ, anyone (any other module) have any input on this
CiviCRM is aggressively adding hooks over the past year.
Simple examples: - Form validation. I'm editing a contact and in my org we have specific validation requirements for a contact field (External ID for example). So you can implement a $moduleName_civicrm_validate function which will get called when the form is saved.
- Setting default value for a custom field: you can implement _civicrm_buildForm to set default
Another customization option is creating custom versions of CiviCRM templates
If you want to inject content into a page (like add a form field) - you may need to use a combination of the buildForm hook and a customized template. Then you'll probably need to implement the postProcess hook to do something with the additional data.
We have 2 basic types of web content, Form and Page.
If you want to add content to a page you use the pageRun hook AND customize the template.
If you want to extend data available in mail merge you can use the token hook to build a whole class of custom tokens. For example you can create tokens to expose "lastYearsContributionTotal".
Other Tips You can use crmAPI in CiviCRM templates to grab and inject data in a page. You can invoke any API using this "wrapper".
Enable debug tools in Global Settings so you can see what variables are available to your template.
Learn more about CiviCRM Hooks, Template Customization and APIs from these docs: