{"id":1414,"date":"2015-08-05T15:50:13","date_gmt":"2015-08-05T23:50:13","guid":{"rendered":"http:\/\/systemsolver.com\/StatlerBlog\/?p=1414"},"modified":"2015-08-05T15:50:13","modified_gmt":"2015-08-05T23:50:13","slug":"civicrm-modules-extensions-and-hooks","status":"publish","type":"post","link":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/2015\/08\/05\/civicrm-modules-extensions-and-hooks\/","title":{"rendered":"CiviCRM modules, extensions and hooks"},"content":{"rendered":"<p>These are notes to myself about customizing CiviCRM. I have CiviCRM in Drupal but the notes are not specific to Drupal, at least I don&#8217;t think they are.<\/p>\n<h4>Customize Built-in, Profile, Contribution and Event Registration Screens<\/h4>\n<p style=\"padding-left: 30px;\"><a href=\"http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/Customize+Built-in%2C+Profile%2C+Contribution+and+Event+Registration+Screens\">http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/Customize+Built-in%2C+Profile%2C+Contribution+and+Event+Registration+Screens<\/a><\/p>\n<p style=\"padding-left: 30px;\">Related: <a href=\"http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/Using+the+API\">http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/Using+the+API<\/a><\/p>\n<p style=\"padding-left: 30px;\">There are at least 5 different ways of using an API function.\u00a0In each environment, the API uses the same names for entities, actions, and parameters, but the syntax is slightly different. Entities are the data collections you want to operate on, for example Contact, Event or Group. The actions are the thing you want to do to the entity, for example get, create, delete or update.<\/p>\n<p style=\"padding-left: 30px;\">You can use the API:<\/p>\n<ol>\n<li style=\"padding-left: 30px;\">as a PHP function, to run your own code on the same server as CiviCRM<\/li>\n<li style=\"padding-left: 30px;\">via the AJAX interface, to be called from JavaScript code<\/li>\n<li style=\"padding-left: 30px;\">via the REST* interface, can be called from another server via http\/https calls<\/li>\n<li style=\"padding-left: 30px;\">as a Smarty function to add data to templates<\/li>\n<li style=\"padding-left: 30px;\">from drush on the command line for Drupal installations.<\/li>\n<\/ol>\n<h4>Limit the list of contacts to search when assigning a case role<\/h4>\n<p style=\"padding-left: 60px;\"><a href=\"http:\/\/civicrm.stackexchange.com\/questions\/728\/limit-the-list-of-contacts-to-search-when-assigning-a-case-role?rq=1\">http:\/\/civicrm.stackexchange.com\/questions\/728\/limit-the-list-of-contacts-to-search-when-assigning-a-case-role?rq=1<\/a><\/p>\n<p style=\"padding-left: 60px;\">The contact selector is an <a href=\"http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/EntityRef+Fields\" rel=\"nofollow\">EntityRef field<\/a>. If you&#8217;d like to &#8220;enforce&#8221; a certain group or other filter on this field, you can do so with a small amount of custom code on your site.<\/p>\n<p style=\"padding-left: 60px;\">Modifying a form in CiviCRM depends on how the form is generated. Because this form is written in javascript, I recommend adding a custom js file to the CiviCase dashboard screen. It simply needs to add <a href=\"https:\/\/api.jquery.com\/data\/\" rel=\"nofollow\">data<\/a> to the two fields (<code>edit_role_contact_id<\/code> and <code>add_role_contact_id<\/code>) that specifies the group_id of your group.<\/p>\n<p style=\"padding-left: 60px;\">You can either use a custom module\/plugin on your website or <a href=\"http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/Create+a+Module+Extension\" rel=\"nofollow\">create an extension<\/a> to add your javascript file using <a href=\"http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/Resource+Reference\" rel=\"nofollow\">CRM_Core_Resources<\/a> from <a href=\"http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/Hook+Reference\" rel=\"nofollow\">a hook<\/a>. <a href=\"http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/hook_civicrm_caseSummary\" rel=\"nofollow\">hook_civicrm_caseSummary<\/a> might be a good one, you wouldn&#8217;t be using it for exactly its intended purpose but it fires on the right screen.<\/p>\n<div class=\"post-text\" style=\"padding-left: 30px;\">\n<p style=\"padding-left: 30px;\">The contact selector is an <a href=\"http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/EntityRef+Fields\" rel=\"nofollow\">EntityRef field<\/a>. If you&#8217;d like to &#8220;enforce&#8221; a certain group or other filter on this field, you can do so with a small amount of custom code on your site.<\/p>\n<p style=\"padding-left: 30px;\">Modifying a form in CiviCRM depends on how the form is generated. Because this form is written in javascript, I recommend adding a custom js file to the CiviCase dashboard screen. It simply needs to add <a href=\"https:\/\/api.jquery.com\/data\/\" rel=\"nofollow\">data<\/a> to the two fields (<code>edit_role_contact_id<\/code> and <code>add_role_contact_id<\/code>) that specifies the group_id of your group.<\/p>\n<p style=\"padding-left: 30px;\">You can either use a custom module\/plugin on your website or <a href=\"http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/Create+a+Module+Extension\" rel=\"nofollow\">create an extension<\/a> to add your javascript file using <a href=\"http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/Resource+Reference\" rel=\"nofollow\">CRM_Core_Resources<\/a> from <a href=\"http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/Hook+Reference\" rel=\"nofollow\">a hook<\/a>. <a href=\"http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/hook_civicrm_caseSummary\" rel=\"nofollow\">hook_civicrm_caseSummary<\/a> might be a good one, you wouldn&#8217;t be using it for exactly its intended purpose but it fires on the right screen.<\/p>\n<\/div>\n<h4>Configure extensions<\/h4>\n<p><a href=\"http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/Extensions\">http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/Extensions<\/a><\/p>\n<h4>Install civix for civicrm<\/h4>\n<p><a href=\"http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/Create+an+Extension\">http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/Create+an+Extension<\/a><\/p>\n<p><a href=\"https:\/\/github.com\/totten\/civix\/\">https:\/\/github.com\/totten\/civix\/<\/a><\/p>\n<h4>Create a module extension<\/h4>\n<p><a href=\"http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/Create+a+Module+Extension\">http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/Create+a+Module+Extension<\/a><\/p>\n<h4>Module to demonstrate CiviCRM hooks<\/h4>\n<p><a href=\"https:\/\/github.com\/eileenmcnaughton\/civicrm_developer\">https:\/\/github.com\/eileenmcnaughton\/civicrm_developer<\/a><\/p>\n<h4>Hook reference<\/h4>\n<p style=\"padding-left: 60px;\"><a href=\"http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/Hook+Reference#HookReference-Goalsandbackground\">http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/Hook+Reference#HookReference-Goalsandbackground<\/a><\/p>\n<p style=\"padding-left: 60px;\">hook_civicrm_buildForm &#8212; This hook is invoked when building a CiviCRM form. This hook should also be used to set the default values of a form element, to change form elements attributes, or even to add new fields to a form.<\/p>\n<p style=\"padding-left: 60px;\"><a href=\"http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/hook_civicrm_buildForm\">http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/hook_civicrm_buildForm<\/a><\/p>\n<p style=\"padding-left: 60px;\">Examples:<\/p>\n<p style=\"padding-left: 60px;\">set \u201cAssigned To\u201d for an Activity to default to the logged-in user name?<\/p>\n<p style=\"padding-left: 60px;\"><a href=\"http:\/\/civicrm.stackexchange.com\/questions\/4399\/how-can-i-set-assigned-to-for-an-activity-to-default-to-the-logged-in-user-nam\">http:\/\/civicrm.stackexchange.com\/questions\/4399\/how-can-i-set-assigned-to-for-an-activity-to-default-to-the-logged-in-user-nam<\/a><\/p>\n<p style=\"padding-left: 60px;\">You cannot influence the activity source contact with the membership API Create action, but interesting discussion<\/p>\n<p style=\"padding-left: 60px;\"><a href=\"http:\/\/civicrm.stackexchange.com\/questions\/4396\/can-i-influence-the-activity-source-contact-with-the-membership-api-create-actio\">http:\/\/civicrm.stackexchange.com\/questions\/4396\/can-i-influence-the-activity-source-contact-with-the-membership-api-create-actio<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>These are notes to myself about customizing CiviCRM. I have CiviCRM in Drupal but the notes are not specific to Drupal, at least I don&#8217;t think they are. Customize Built-in, Profile, Contribution and Event Registration Screens http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/Customize+Built-in%2C+Profile%2C+Contribution+and+Event+Registration+Screens Related: http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/Using+the+API There are at least 5 different ways of using an API function.\u00a0In each environment, the API [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1414","post","type-post","status-publish","format-standard","hentry","category-civicrm"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/posts\/1414","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/comments?post=1414"}],"version-history":[{"count":0,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/posts\/1414\/revisions"}],"wp:attachment":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/media?parent=1414"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/categories?post=1414"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/tags?post=1414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}