Answers.Body: <p>The event field on participant form uses event api to retrieve events. You can easily alter the list by implementing <a href="https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_apiWrappers/" rel="nofollow noreferrer">hook_civicrm_apiWrappers</a> hook by adding additional parameter to exclude recurring event in $params of api probably <code>'parent_event_id' =&gt; ['IS NULL' =&gt; 1]</code>. </p>
  
  <p>Or using buildform hook try adding parent_event_id condition in data-api-params of the field(element).</p>
  
  <pre><code>if ('CRM_Event_Form_Participant' == $formName) {
      $elementIndex = CRM_Utils_Array::value('event_id', $form-&gt;_elementIndex);
      if (empty($elementIndex)) {
        return;
      }
      $element = &amp; $form-&gt;_elements[$elementIndex];
      $dataApiParams = json_decode($element-&gt;_attributes['data-api-params'], TRUE);
      $dataApiParams['params'] = ['parent_event_id' =&gt; ['IS NULL' =&gt; 1]];
      $element-&gt;_attributes['data-api-params'] = json_encode($dataApiParams);
    }
  </code></pre>
  
  <p>Cheers</p>
  
  <p>Pradeep</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-01T21:47:34.603Z
Answers.Text: Hi @pradeep, can you provide an example, I see the following source code in the Event Dropdown element,kindly check the updated answer.
Answers.UserDisplayName: harshal
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-01T21:50:10.443Z
Answers.Text: 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
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-01T21:52:07.480Z
Answers.Text: Hi @Pradeep, yes I am trying ,let me update the question on what I tried.
Answers.UserDisplayName: harshal
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-01T21:56:44.670Z
Answers.Text: Just updated my answer on how you can use buildform
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-01T22:05:41.430Z
Answers.Text: Really sorry, but I have never added condition in data-api-params, hence was looking for an example on how i can add it in hook_buildForm()
Answers.UserDisplayName: harshal
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-01T23:22:30.880Z
Answers.Text: Updated my answer to include the snippet, but i havent tested it. But it should be something like that
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-02T02:45:58.990Z
Answers.Text: Thanks , i will test it, you are very quick.
Answers.UserDisplayName: harshal
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-02T11:08:51.120Z
Answers.Text: Let us know how it went
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-03T06:15:15.843Z
Answers.Text: Hi @Pradeep, yes I finally created an event_type_id for child events because parent_event_id was not able to distinguish between parent(first event) and child event (subsequent event) as parent_event_id was present for both parent and child event, hence I added condition in the params above as ['params']['event_type_id']['!='] = 8(where 8 is an event_type id named Repeat for child event) repeat event type is added hook_civicrm_post when RecurringEntity is created and parent_id != entity_id,  if you feel it can improved, let me know, I will improve on it.will post my answer in detail later
Answers.UserDisplayName: harshal
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-12T16:23:19.207Z
Answers.Text: Hi @Pradeep,  the above code gives an error in the console 500 error, and which results in payment blocked not displayed when its a paid event.
Answers.UserDisplayName: harshal
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-12T16:36:47.403Z
Answers.Text: The intension was to provide a way on how you can do that rather exact working solution. You will need to debug $form why its failing in certain case and then add condition based on it.
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-12T16:54:42.987Z
Answers.Text: Hi @pradeep,I completely agree with your point, I will send you where the error ,maybe its some core issue.
Answers.UserDisplayName: harshal
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-12T18:31:04.347Z
Answers.Text: Hi Pradeep, I have updated my question,kindly have a re look at it
Answers.UserDisplayName: harshal
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-12T20:17:40.827Z
Answers.Text: Updated the code snippet with required validation!
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-13T03:46:39.630Z
Answers.Text: Hi Pradeep, thanks a lot you have been helping in my every civicrm problems !!
Answers.UserDisplayName: harshal
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-01T10:24:22.150Z
Answers.LastActivityDate: 2019-02-12T20:17:19.127Z
Answers.LastEditDate: 2019-02-12T20:17:19.127Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>On Register Particpant Page, I see list of all Events under Event dropdown<br>
  As per the requirement, I am using Recurring Entity to have repeat <br>events,so I need to hide repeat events and display only parent events<br>
  How can we alter the results in the Event dropdown 
  <a href="https://i.sstatic.net/BPIAB.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/BPIAB.png" alt="enter image description here"></a></p>
  
  <p>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 )</p>
  
  <pre><code> $apiRequest['entity'] == 'event'
  
  /**
   * Implements hook_civicrm_apiWrappers
   */
  function custom_changes_civicrm_apiWrappers(&amp;$wrappers, $apiRequest) {
  
    if ($apiRequest['entity'] == 'event' ) {
      print_r('&lt;pre&gt;');
      print_r($apiRequest);
      print_r($wrappers);
      die('ed'); 
   }
  }
  </code></pre>
  
  <p><a href="https://i.sstatic.net/mi7eP.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/mi7eP.png" alt="enter image description here"></a></p>
  
  <p>On adding the code answered below</p>
  
  <pre><code>if ('CRM_Event_Form_Participant' == $formName) {
      $elementIndex = $form-&gt;_elementIndex['event_id'];
      $element = &amp; $form-&gt;_elements[$elementIndex];
      $dataApiParams = json_decode($element-&gt;_attributes['data-api-params'], TRUE);
      $dataApiParams['params'] = ['parent_event_id' =&gt; ['IS NULL' =&gt; 1]];
      $element-&gt;_attributes['data-api-params'] = json_encode($dataApiParams);   }
  </code></pre>
  
  <p>I get an error (when I comment I don't get the error).</p>
  
  <blockquote>
    <p>Error: Call to undefined method stdClass::getName() in
    HTML_QuickForm->accept() (line 1686 of
    csites\all\modules\civicrm\packages\HTML\QuickForm.php).</p>
  </blockquote>
  
  <p>To fix that I actually went to QuickForm.php and added an if condition as seen below</p>
  
  <pre><code>if(method_exists($element,'getName')
  </code></pre>
  
  <p>Is that a correct method and if not , how can I debug that further based on the error log.</p>
  
  <pre><code> function accept(&amp;$renderer)
      {
          $renderer-&gt;startForm($this);
          foreach (array_keys($this-&gt;_elements) as $key) {
              $element =&amp; $this-&gt;_elements[$key];
              if (method_exists($element,'getName')){
              $elementName = $element-&gt;getName();
              $required    = ($this-&gt;isElementRequired($elementName) &amp;&amp; !$element-&gt;isFrozen());
              $error       = $this-&gt;getElementError($elementName);
              $element-&gt;accept($renderer, $required, $error);
              }
          }
          $renderer-&gt;finishForm($this);
      } // end func accept
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-01T10:04:28.203Z
Comments.Text: If you need to list only the parent event - then you need some development to achieve the same
Comments.UserDisplayName: Ramesh - ARTECH Consultancy
Tags: <civievent>
Title: How to alter Event Dropdown values from Register Participant or New Event Registration Page?
ThreadText: # How to alter Event Dropdown values from Register Participant or New Event Registration Page?
  
  (Asked by: username_0 on 2019-02-01)
  
  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](https://i.sstatic.net/BPIAB.png)](https://i.sstatic.net/BPIAB.png)
  
  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' ) {
      print_r('<pre>');
      print_r($apiRequest);
      print_r($wrappers);
      die('ed'); 
   }
  }
  
  ```
  
  [![enter image description here](https://i.sstatic.net/mi7eP.png)](https://i.sstatic.net/mi7eP.png)
  
  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
  
  ```
  if(method_exists($element,'getName')
  
  ```
  
  Is that a correct method and if not , how can I debug that further based on the error log.
  
  ```
   function accept(&$renderer)
      {
          $renderer->startForm($this);
          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);
              }
          }
          $renderer->finishForm($this);
      } // end func accept
  
  ```
  
  **Tags:** civievent
  
  > **Comments:**
  > **username_1**: If you need to list only the parent event - then you need some development to achieve the same  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-02-01. Score: 2
  
  The event field on participant form uses event api to retrieve events. You can easily alter the list by implementing [hook\_civicrm\_apiWrappers](https://docs.civicrm.org/dev/en/latest/hooks/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)) {
        return;
      }
      $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);
    }
  
  ```
  
  Cheers
  
  username_2
  
  > **Comments:**
  > **username_0**: Hi @username_2, can you provide an example, I see the following source code in the Event Dropdown element,kindly check the updated answer.  
  > **username_2**: 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  
  > **username_0**: Hi @username_2, yes I am trying ,let me update the question on what I tried.  
  > **username_2**: Just updated my answer on how you can use buildform  
  > **username_0**: Really sorry, but I have never added condition in data-api-params, hence was looking for an example on how i can add it in hook_buildForm()  
  > **username_2**: Updated my answer to include the snippet, but i havent tested it. But it should be something like that  
  > **username_0**: Thanks , i will test it, you are very quick.  
  > **username_2**: Let us know how it went  
  > **username_0**: Hi @username_2, yes I finally created an event_type_id for child events because parent_event_id was not able to distinguish between parent(first event) and child event (subsequent event) as parent_event_id was present for both parent and child event, hence I added condition in the params above as ['params']['event_type_id']['!='] = 8(where 8 is an event_type id named Repeat for child event) repeat event type is added hook_civicrm_post when RecurringEntity is created and parent_id != entity_id,  if you feel it can improved, let me know, I will improve on it.will post my answer in detail later  
  > **username_0**: Hi @username_2,  the above code gives an error in the console 500 error, and which results in payment blocked not displayed when its a paid event.  
  > **username_2**: The intension was to provide a way on how you can do that rather exact working solution. You will need to debug $form why its failing in certain case and then add condition based on it.  
  > **username_0**: Hi @username_2,I completely agree with your point, I will send you where the error ,maybe its some core issue.  
  > **username_0**: Hi username_2, I have updated my question,kindly have a re look at it  
  > **username_2**: Updated the code snippet with required validation!  
  > **username_0**: Hi username_2, thanks a lot you have been helping in my every civicrm problems !!  
  
  ---
  
  