2

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);
  }
3

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

  • 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 – harshal Jan 14 at 4:24
  • 1
    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. – lcdservices Jan 14 at 16:33
  • 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? – harshal Jan 16 at 4:46
  • Hi, I have added question for the same here : civicrm.stackexchange.com/questions/28087/… Your answer would be highly appreciated.! thanks – harshal Jan 16 at 4:55

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.