Fixed by default payment instrument to add payment fields
This commit is contained in:
		@@ -185,6 +185,30 @@ function checknumberpaymentmethod_civicrm_preProcess($formName, &$form) {
 | 
				
			|||||||
 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_preProcess
 | 
					 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_preProcess
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function checknumberpaymentmethod_civicrm_buildForm($formName, &$form) {
 | 
					function checknumberpaymentmethod_civicrm_buildForm($formName, &$form) {
 | 
				
			||||||
 | 
					  if (in_array($formName, array(
 | 
				
			||||||
 | 
					    "CRM_Contribute_Form_Contribution",
 | 
				
			||||||
 | 
					    "CRM_Member_Form_Membership",
 | 
				
			||||||
 | 
					    "CRM_Event_Form_Participant",
 | 
				
			||||||
 | 
					    "CRM_Contribute_Form_AdditionalPayment",
 | 
				
			||||||
 | 
					    "CRM_Member_Form_MembershipRenewal",
 | 
				
			||||||
 | 
					  ))) {
 | 
				
			||||||
 | 
					    if ($form->getVar('_action') & CRM_Core_Action::DELETE) {
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if ($formName == 'CRM_Contribute_Form_AdditionalPayment'
 | 
				
			||||||
 | 
					      && $form->getVar('_view') == 'transaction'
 | 
				
			||||||
 | 
					      && ($form->getVar('_action') & CRM_Core_Action::BROWSE)
 | 
				
			||||||
 | 
					    ) {
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (!empty($form->_defaultValues['payment_instrument_id'])) {
 | 
				
			||||||
 | 
					      _checknumberpaymentmethod_add_payment_fields(
 | 
				
			||||||
 | 
					        $form,
 | 
				
			||||||
 | 
					        $form->_defaultValues['payment_instrument_id']
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (('CRM_Contribute_Form_AdditionalPayment' == $formName
 | 
					  if (('CRM_Contribute_Form_AdditionalPayment' == $formName
 | 
				
			||||||
    && $form->getVar('_view') == 'transaction'
 | 
					    && $form->getVar('_view') == 'transaction'
 | 
				
			||||||
    && ($form->getVar('_action') & CRM_Core_Action::BROWSE))
 | 
					    && ($form->getVar('_action') & CRM_Core_Action::BROWSE))
 | 
				
			||||||
@@ -192,9 +216,12 @@ function checknumberpaymentmethod_civicrm_buildForm($formName, &$form) {
 | 
				
			|||||||
    || 'CRM_Contribute_Form_ContributionView' == $formName
 | 
					    || 'CRM_Contribute_Form_ContributionView' == $formName
 | 
				
			||||||
  ) {
 | 
					  ) {
 | 
				
			||||||
    $payments = $form->get_template_vars('payments');
 | 
					    $payments = $form->get_template_vars('payments');
 | 
				
			||||||
 | 
					    if ($payments) {
 | 
				
			||||||
      _checknumberpaymentmethod_alterpayments($payments);
 | 
					      _checknumberpaymentmethod_alterpayments($payments);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    $form->assign('payments', $payments);
 | 
					    $form->assign('payments', $payments);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if ('CRM_Admin_Form_Preferences_Contribute' == $formName) {
 | 
					  if ('CRM_Admin_Form_Preferences_Contribute' == $formName) {
 | 
				
			||||||
    $form->addElement(
 | 
					    $form->addElement(
 | 
				
			||||||
      'select',
 | 
					      'select',
 | 
				
			||||||
@@ -210,15 +237,9 @@ function checknumberpaymentmethod_civicrm_buildForm($formName, &$form) {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if ($formName == 'CRM_Financial_Form_Payment' && !empty($form->paymentInstrumentID)) {
 | 
					  if ($formName == 'CRM_Financial_Form_Payment' && !empty($form->paymentInstrumentID)) {
 | 
				
			||||||
    $paymentInstrumentsFromSettings = civicrm_api3('Setting', 'getvalue', [
 | 
					    _checknumberpaymentmethod_add_payment_fields($form, $form->paymentInstrumentID);
 | 
				
			||||||
      'name' => 'check_payment_instrument_ids',
 | 
					 | 
				
			||||||
    ]);
 | 
					 | 
				
			||||||
    if (in_array($form->paymentInstrumentID, $paymentInstrumentsFromSettings)) {
 | 
					 | 
				
			||||||
      $form->assign('paymentFields', array('check_number'));
 | 
					 | 
				
			||||||
      $form->add('text', 'check_number', ts('Check Number'));
 | 
					 | 
				
			||||||
      $form->assign('paymentTypeLabel', ts('Check Information'));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if ('CRM_Financial_Form_PaymentEdit' == $formName) {
 | 
					  if ('CRM_Financial_Form_PaymentEdit' == $formName) {
 | 
				
			||||||
    $paymentInstrumentsFromSettings = civicrm_api3('Setting', 'getvalue', [
 | 
					    $paymentInstrumentsFromSettings = civicrm_api3('Setting', 'getvalue', [
 | 
				
			||||||
      'name' => 'check_payment_instrument_ids',
 | 
					      'name' => 'check_payment_instrument_ids',
 | 
				
			||||||
@@ -246,6 +267,23 @@ function checknumberpaymentmethod_civicrm_buildForm($formName, &$form) {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Add payment fields to form.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param object $form
 | 
				
			||||||
 | 
					 * @param int $paymentInstrumentID
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function _checknumberpaymentmethod_add_payment_fields(&$form, $paymentInstrumentID) {
 | 
				
			||||||
 | 
					  $paymentInstrumentsFromSettings = civicrm_api3('Setting', 'getvalue', [
 | 
				
			||||||
 | 
					    'name' => 'check_payment_instrument_ids',
 | 
				
			||||||
 | 
					  ]);
 | 
				
			||||||
 | 
					  if (in_array($paymentInstrumentID, $paymentInstrumentsFromSettings)) {
 | 
				
			||||||
 | 
					    $form->assign('paymentFields', array('check_number'));
 | 
				
			||||||
 | 
					    $form->add('text', 'check_number', ts('Check Number'));
 | 
				
			||||||
 | 
					    $form->assign('paymentTypeLabel', ts('Check Information'));
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Implements hook_civicrm_pre().
 | 
					 * Implements hook_civicrm_pre().
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user