I am excited to be working with civicrm, but I am quite frustrated at this point and so I hope someone can help me.

I can see how valuable hooks are, and it seems like they are actually very basic to implement, but I need a small amount of pre-knowledge to use them. I have read every link I could find about hooks to change forms and yet I find myself lost.

I did find one example that fit my needs exactly, and would be a great learning experience ... but the description leaves out a lot of necessary information for someone as new as me.

Can someone walk me though implementing this? It comes from How can I set “Assigned To” for an Activity to default

The extension mentioned in the comment above is:

function myextension_civicrm_buildForm($formName, &$form) { if ($formName == 'CRM_Activity_Form_Activity' && $form->action == CRM_Core_Action::ADD) { $form->setDefaults(array('assignee_contact_id' => $form->_currentUserId)); } }

  • How do I find the 'create activity' form this relates to?

I got that answer myself -- CRM _ Activity _ Form _ Activity means the php file is in

/var/www/drupal/sites/all/modules/civicrm/CRM/Activity/Form and then activity.php

  • Do I copy the form to my /var/www/drupal/sites/all/modules/civicrm_extensions directory?
  • Do I put that function inside the form I copied?
  • Do I create that as a file?
  • If a file, what do I name it?
  • Where do I put the extension once I create it?

You are all very helpful and I appreciate it. Thank you in advance for any help you can give me on this problem I face.

Just a note about searching for answers: About a month or two ago I found a web page that explained some of this to me but for the life of me I fail to find that page today. I did find a lot of links that looked like they could help but a whole mess of them led to (Page Not Found) on http://wiki.civicrm.org/confluence/display/CRMDOC/. Seems a lot of pages were deleted or renamed.

Thanks again.

  • Note that the example code from that answer has just been updated to fix an error. You might want to change your hook code as well.
    – Coleman
    Commented Aug 18, 2015 at 12:47

2 Answers 2


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 presumes that you have a basic knowledge of PHP, Unix, and object-oriented programming. If that's not a skill you're going to learn today, and you want to cheat a little - take an existing extension and hack it! Download an existing function, preferably one that does very little, and modify it to your needs. I just uploaded an extension to Github that fits this need exactly here.

  • Thank you. Do I put that in /var/www/drupal/sites/all/modules/civicrm_extensions and then inside a folder, in your case, namedcontributionpagecustomizations?
    – OregonJohn
    Commented Aug 18, 2015 at 5:41
  • Thank you. I got that to work, renaming your folder, php file names and I replaced your 'contributionpagecustomizations' with my 'formcustomization' in the php files. Got it to install in 'Manage Extension' but --- if ($formName == 'CRM_Activity_Form_Activity' && $form->getaction() == CRM_Core_Action::ADD) {$form->setDefaults(array('assignee_contact_id' => $form->_currentUserId)); --- did not set the default assignee to current user. Any ideas? Thanks in advance.
    – OregonJohn
    Commented Aug 18, 2015 at 8:07
  • Got it. That did work, just had to refresh the page! Thank you, new horizons await me!!!
    – OregonJohn
    Commented Aug 18, 2015 at 8:11

There is also a pretty basic example here: https://github.com/CiviCooP/no.maf.oppgavexml This extension creates 2 files, introduces a page and a form. Might be able to give you some more understanding. But the real recommendation would be to take part in a CiviCRM developer training or CiviCRM sprint? Depending on where you are in the world you might be interested in a developer training in London that is coming up?

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.