0

I'd like to change the form that opens when adding an Activity to a Case (depending on activity type). Specifically, I'd like to add a field. I tried finding the fields I want to change in sites/all/modules/civicrm/CRM/Case/Form/Activity.php but couldn't find them. It seems like the buildQuickForm() function is only creating some of the visible fields but not all. I also thought about writing an extension based on the hook_civicrm_buildForm function. I want to start checking if $formName == 'CRM_Case_Form_Activity' but after that I don't really know where to start. Can anyone give me a hint?

Edit: I found an extension changing the same location looking like this (How can I set "Assigned To" for an Activity to default to the logged-in user name?):

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

Is there anything like $form->addField or something?

  • Did you look at custom fields? (Admin - Customize - Custom Fields) You can create them for activities for either all types or just some types. – Demerit Oct 20 at 11:22
  • I tried that now, but the field doesn't appear. I think this is because the activity where I want to add a field is not a normal activity but a "create email" activity – emma Oct 20 at 11:46
  • Ok yes emails are a bit different. – Demerit Oct 20 at 11:48
1

you need to create an extension and use the buildForm hook.

More information on creating an extension can be found here: https://docs.civicrm.org/dev/en/latest/extensions/

More information on the buildForm hook: https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm/ This contains an example of adding a field.

Another example of adding a field with the buildForm hook:

if ($studyNumber) {
  $form->addElement('text', 'study_number', "Study Number", ['readonly' => 'readonly']);
  $form->setDefaults(['study_number' => $studyNumber]);
  CRM_Core_Region::instance('page-body')->add(['template' => 'CRM/Nihrbackbone/nbr_study_number.tpl',]);
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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