On Register Particpant Page, I see list of all Events under Event dropdown
As per the requirement, I am using Recurring Entity to have repeat
events,so I need to hide repeat events and display only parent events
How can we alter the results in the Event dropdown enter image description here

The Event dropdown has this form structure (from hook_buildForm) When I add a condition and try to print variables inside it on New Participant Registration it does not show up.(probably since its entering )

 $apiRequest['entity'] == 'event'

 * Implements hook_civicrm_apiWrappers
function custom_changes_civicrm_apiWrappers(&$wrappers, $apiRequest) {

  if ($apiRequest['entity'] == 'event' ) {

enter image description here

On adding the code answered below

if ('CRM_Event_Form_Participant' == $formName) {
    $elementIndex = $form->_elementIndex['event_id'];
    $element = & $form->_elements[$elementIndex];
    $dataApiParams = json_decode($element->_attributes['data-api-params'], TRUE);
    $dataApiParams['params'] = ['parent_event_id' => ['IS NULL' => 1]];
    $element->_attributes['data-api-params'] = json_encode($dataApiParams);   }

I get an error (when I comment I don't get the error).

Error: Call to undefined method stdClass::getName() in HTML_QuickForm->accept() (line 1686 of csites\all\modules\civicrm\packages\HTML\QuickForm.php).

To fix that I actually went to QuickForm.php and added an if condition as seen below


Is that a correct method and if not , how can I debug that further based on the error log.

 function accept(&$renderer)
        foreach (array_keys($this->_elements) as $key) {
            $element =& $this->_elements[$key];
            if (method_exists($element,'getName')){
            $elementName = $element->getName();
            $required    = ($this->isElementRequired($elementName) && !$element->isFrozen());
            $error       = $this->getElementError($elementName);
            $element->accept($renderer, $required, $error);
    } // end func accept
  • 1
    If you need to list only the parent event - then you need some development to achieve the same Feb 1, 2019 at 10:04

1 Answer 1


The event field on participant form uses event api to retrieve events. You can easily alter the list by implementing hook_civicrm_apiWrappers hook by adding additional parameter to exclude recurring event in $params of api probably 'parent_event_id' => ['IS NULL' => 1].

Or using buildform hook try adding parent_event_id condition in data-api-params of the field(element).

if ('CRM_Event_Form_Participant' == $formName) {
    $elementIndex = CRM_Utils_Array::value('event_id', $form->_elementIndex);
    if (empty($elementIndex)) {
    $element = & $form->_elements[$elementIndex];
    $dataApiParams = json_decode($element->_attributes['data-api-params'], TRUE);
    $dataApiParams['params'] = ['parent_event_id' => ['IS NULL' => 1]];
    $element->_attributes['data-api-params'] = json_encode($dataApiParams);



  • Hi @pradeep, can you provide an example, I see the following source code in the Event Dropdown element,kindly check the updated answer.
    – harshal
    Feb 1, 2019 at 21:47
  • 1
    I said to use api wrapper hook to add additional condition, the documentation is straight forward,i think you will understand if you use it Feb 1, 2019 at 21:50
  • Hi @Pradeep, yes I am trying ,let me update the question on what I tried.
    – harshal
    Feb 1, 2019 at 21:52
  • 1
    Just updated my answer on how you can use buildform Feb 1, 2019 at 21:56
  • 1
    Updated the code snippet with required validation! Feb 12, 2019 at 20:17

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.