Answers.Body: <p>You will need to over-ride the button to include existing + new button through buildform. The other option is to add button using smarty in tpl file using below snippet</p>
  
  <pre><code>{crmButton p='civicrm/request' q="action=browse&amp;reset=1&amp;gid=$gid" icon="th-list"}{ts}Request for Approval{/ts}{/crmButton}
  </code></pre>
  
  <p>HTH</p>
  
  <p>Pradeep</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-14T04:24:30.163Z
Answers.Text: Hi @Pradeep, an example of over-ride the button to include existing would be highly appreciated, I am updating my post to add more details
Answers.UserDisplayName: harshal
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-14T16:33:26.417Z
Answers.Text: Try getting the buttons element first, then adding your new button and using addButtons to add the entire set to the form. Something like $buttons = $form->getElement('buttons'); 
  
  I'm not 100% sure "buttons" is the element name. view $form and look for $form->_elementIndex to get the array of elements.
Answers.UserDisplayName: lcdservices
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-16T04:46:02.523Z
Answers.Text: Hi @Pradeep, adding the above button gives an error Unable to contact Network with no error in the drupal logs, any idea, I tried fixing it but could find any solution, can you provide insight on what p and q attributes in the above answer mean so I can alter according , I have created a custom callback inside p="drupal/event-workflow" can that cause an issue , if yes, what can we do to fix it?
Answers.UserDisplayName: harshal
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-16T04:55:00.477Z
Answers.Text: Hi, I have added question for the same here : https://civicrm.stackexchange.com/questions/28087/i-am-adding-crmbutton-in-the-template-for-eventinfo-tpl-how-can-i-add-drupal-c
  Your answer would be highly appreciated.! thanks
Answers.UserDisplayName: harshal
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-13T21:07:18.453Z
Answers.LastActivityDate: 2019-01-13T21:07:18.453Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>I need to add one more button to an event form but right now when I use </p>
  
  <pre><code>addButtons
  </code></pre>
  
  <p>it overrides existing buttons
  How can I make sure the buttons which I add are updated instead of replacing the existing ones?</p>
  
  <pre><code>function custom_changes_civicrm_buildForm($formName, &amp;$form){
    if($formName == 'CRM_Event_Form_ManageEvent_EventInfo' &amp;&amp; $user-&gt;uid){
          $buttons = array(
          array(
            'type' =&gt; 'upload',
            'name' =&gt; ts('Request for Approval'),
            'isDefault' =&gt; TRUE,
          ),
        );
        $form-&gt;addButtons($buttons);
  
    }
  }
  </code></pre>
  
  <p>In the CRM\Event\Form\ManageEvent.php<br>
  I see there are protected variables, which I am unable to add it in the conditions inside hook_buildForm<br>
  e.g. _cancelURL, _single , so how can I override it using hook_buildForm , an <br>example would be helpful.<br></p>
  
  <pre><code> /**
     * Build the form object.
     */
    public function buildQuickForm() {
      $session = CRM_Core_Session::singleton();
  
      $this-&gt;_cancelURL = CRM_Utils_Array::value('cancelURL', $_POST);
  
      if (!$this-&gt;_cancelURL) {
        if ($this-&gt;_isTemplate) {
          $this-&gt;_cancelURL = CRM_Utils_System::url('civicrm/admin/eventTemplate',
            'reset=1'
          );
        }
        else {
          $this-&gt;_cancelURL = CRM_Utils_System::url('civicrm/event/manage',
            'reset=1'
          );
        }
      }
  
      if ($this-&gt;_cancelURL) {
        $this-&gt;addElement('hidden', 'cancelURL', $this-&gt;_cancelURL);
      }
  
      if ($this-&gt;_single) {
        $buttons = array(
          array(
            'type' =&gt; 'upload',
            'name' =&gt; ts('Save'),
            'isDefault' =&gt; TRUE,
          ),
          array(
            'type' =&gt; 'upload',
            'name' =&gt; ts('Save and Done'),
            'spacing' =&gt; '&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;',
            'subName' =&gt; 'done',
          ),
          array(
            'type' =&gt; 'cancel',
            'name' =&gt; ts('Cancel'),
          ),
        );
        $this-&gt;addButtons($buttons);
      }
      else {
        $buttons = array();
        if (!$this-&gt;_first) {
          $buttons[] = array(
            'type' =&gt; 'back',
            'name' =&gt; ts('Previous'),
            'spacing' =&gt; '&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;',
          );
        }
        $buttons[] = array(
          'type' =&gt; 'upload',
          'name' =&gt; ts('Continue'),
          'spacing' =&gt; '&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;',
          'isDefault' =&gt; TRUE,
        );
        $buttons[] = array(
          'type' =&gt; 'cancel',
          'name' =&gt; ts('Cancel'),
        );
  
        $this-&gt;addButtons($buttons);
      }
      $session-&gt;replaceUserContext($this-&gt;_cancelURL);
      $this-&gt;add('hidden', 'is_template', $this-&gt;_isTemplate);
    }
  </code></pre>
  
Tags: <quickform><button>
Title: how to get list of all buttons in civicrm hook_buildform?
ThreadText: # how to get list of all buttons in civicrm hook_buildform?
  
  (Asked by: username_0 on 2019-01-13)
  
  I need to add one more button to an event form but right now when I use 
  addButtons
  
  it overrides existing buttons
  How can I make sure the buttons which I add are updated instead of replacing the existing ones?
  function custom_changes_civicrm_buildForm($formName, &$form){
    if($formName == 'CRM_Event_Form_ManageEvent_EventInfo' && $user->uid){
          $buttons = array(
          array(
            'type' => 'upload',
            'name' => ts('Request for Approval'),
            'isDefault' => TRUE,
          ),
        );
        $form->addButtons($buttons);
  
    }
  }
  
  In the CRM\Event\Form\ManageEvent.php
  I see there are protected variables, which I am unable to add it in the conditions inside hook_buildForm
  e.g. _cancelURL, _single , so how can I override it using hook_buildForm , an example would be helpful.
   /**
     * Build the form object.
     */
    public function buildQuickForm() {
      $session = CRM_Core_Session::singleton();
  
      $this->_cancelURL = CRM_Utils_Array::value('cancelURL', $_POST);
  
      if (!$this->_cancelURL) {
        if ($this->_isTemplate) {
          $this->_cancelURL = CRM_Utils_System::url('civicrm/admin/eventTemplate',
            'reset=1'
          );
        }
        else {
          $this->_cancelURL = CRM_Utils_System::url('civicrm/event/manage',
            'reset=1'
          );
        }
      }
  
      if ($this->_cancelURL) {
        $this->addElement('hidden', 'cancelURL', $this->_cancelURL);
      }
  
      if ($this->_single) {
        $buttons = array(
          array(
            'type' => 'upload',
            'name' => ts('Save'),
            'isDefault' => TRUE,
          ),
          array(
            'type' => 'upload',
            'name' => ts('Save and Done'),
            'spacing' => '                 ',
            'subName' => 'done',
          ),
          array(
            'type' => 'cancel',
            'name' => ts('Cancel'),
          ),
        );
        $this->addButtons($buttons);
      }
      else {
        $buttons = array();
        if (!$this->_first) {
          $buttons[] = array(
            'type' => 'back',
            'name' => ts('Previous'),
            'spacing' => '     ',
          );
        }
        $buttons[] = array(
          'type' => 'upload',
          'name' => ts('Continue'),
          'spacing' => '         ',
          'isDefault' => TRUE,
        );
        $buttons[] = array(
          'type' => 'cancel',
          'name' => ts('Cancel'),
        );
  
        $this->addButtons($buttons);
      }
      $session->replaceUserContext($this->_cancelURL);
      $this->add('hidden', 'is_template', $this->_isTemplate);
    }
  
  **Tags:** quickform, button
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-01-13. Score: 2
  
  You will need to over-ride the button to include existing + new button through buildform. The other option is to add button using smarty in tpl file using below snippet
  {crmButton p='civicrm/request' q="action=browse&reset=1&gid=$gid" icon="th-list"}{ts}Request for Approval{/ts}{/crmButton}
  
  HTH
  Pradeep
  
  > **Comments:**
  > **username_0**: Hi @Pradeep, an example of over-ride the button to include existing would be highly appreciated, I am updating my post to add more details  
  > **username_2**: Try getting the buttons element first, then adding your new button and using addButtons to add the entire set to the form. Something like $buttons = $form->getElement('buttons');   I'm not 100% sure "buttons" is the element name. view $form and look for $form->_elementIndex to get the array of elements.  
  > **username_0**: Hi @Pradeep, adding the above button gives an error Unable to contact Network with no error in the drupal logs, any idea, I tried fixing it but could find any solution, can you provide insight on what p and q attributes in the above answer mean so I can alter according , I have created a custom callback inside p="drupal/event-workflow" can that cause an issue , if yes, what can we do to fix it?  
  > **username_0**: Hi, I have added question for the same here : https://civicrm.stackexchange.com/questions/28087/i-am-adding-crmbutton-in-the-template-for-eventinfo-tpl-how-can-i-add-drupal-c Your answer would be highly appreciated.! thanks  
  
  ---
  
  