I'm trying to add a custom field to the Event form programmatically.
So far, I've created a new extension and enabled it, with hook_civicrm_buildForm function in a PHP file. The function's being executed as I can get it stop at a breakpoint. I'm using the addEntityRef method to add a new field.
/**
* Implements hook_civicrm_buildForm()
*
* Adds a field for linking a parent event
*
* @param string $formName
* @param CRM_Event_Form_ManageEvent_EventInfo $form
* @return void
*/
function myExtension_civicrm_buildForm($formName, &$form) {
if ($formName == 'CRM_Event_Form_ManageEvent_EventInfo') {
$form->addEntityRef('my_field', ts('My Field'), [
'entity' => 'Event',
'placeholder' => ts('- any -'),
'select' => ['minimumInputLength' => 0],
]);
$form->buildQuickForm();
}
}
I've followed other posts by adding a template file named my_field.tpl in my extension's templates directory with the contents:
<tr id="my-field-tr">
<td>Parent Event:</td>
<td>{$form.my_field.html}</td>
</tr>
{* Reposition the above block after the Event Type field *}
<script type="text/javascript">
cj('#my-field-tr').insertAfter('.crm-event-manage-eventinfo-form-block-event_type_id')
</script>
But I am struggling to get the field to appear. TIA
$form->buildQuickForm();