Add isBackOffice, isPayLater, getPaymentMode helpers to frontendpaymentformtrait
authorMatthew Wire <mjw@mjwconsult.co.uk>
Fri, 5 Jun 2020 09:45:29 +0000 (10:45 +0100)
committerMatthew Wire <mjw@mjwconsult.co.uk>
Sat, 6 Jun 2020 13:50:22 +0000 (14:50 +0100)
CRM/Event/Form/Registration.php
CRM/Event/Form/Registration/Register.php
CRM/Financial/Form/FrontEndPaymentFormTrait.php

index 8e69eb560e4f8a535aae9225061464d44bc9c021..638f2b8f2dc5317afb543f84fbb8fcb3f3a70dd2 100644 (file)
@@ -78,14 +78,6 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
    */
   public $_additionalParticipantIds;
 
-  /**
-   * The mode that we are in.
-   *
-   * @var string
-   * @protect
-   */
-  public $_mode;
-
   /**
    * The values for the contribution db object.
    *
@@ -182,12 +174,9 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
   public function preProcess() {
     $this->_eventId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     $this->_action = CRM_Utils_Request::retrieve('action', 'Alphanumeric', $this, FALSE, CRM_Core_Action::ADD);
-
     //CRM-4320
     $this->_participantId = CRM_Utils_Request::retrieve('participantId', 'Positive', $this);
-
-    // current mode
-    $this->_mode = ($this->_action == 1024) ? 'test' : 'live';
+    $this->setPaymentMode();
 
     $this->_values = $this->get('values');
     $this->_fields = $this->get('fields');
index a2bc57ef5f7218ca9e58135637a9cca5c4942af6..80e3f7c72f951260a7c18c77f41c358d62bf9383 100644 (file)
@@ -1157,7 +1157,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
     // CRM-3907, skip check for preview registrations
     // CRM-4320 participant need to walk wizard
     if (
-      ($form->_mode == 'test' || $form->_allowConfirmation)
+      ($form->getPaymentMode() === 'test' || $form->_allowConfirmation)
     ) {
       return FALSE;
     }
index 1f296801125c9383c01aa4af6952522b8f9fb852..dbf787e27d616a03c1cab006b796764d363c2436 100644 (file)
  */
 trait CRM_Financial_Form_FrontEndPaymentFormTrait {
 
+  /**
+   * Is pay later enabled on this form?
+   *
+   * @var bool
+   */
+  protected $isPayLater = FALSE;
+
   /**
    * The label for the pay later pseudoprocessor option.
    *
@@ -27,6 +34,58 @@ trait CRM_Financial_Form_FrontEndPaymentFormTrait {
    */
   protected $payLaterLabel;
 
+  /**
+   * Is this a back office form
+   *
+   * @var bool
+   */
+  public $isBackOffice = FALSE;
+
+  /**
+   * The payment mode that we are in ("live" or "test")
+   * This should be protected and retrieved via getPaymentMode() but it's accessed all over the place so we have to leave it public for now.
+   *
+   * @var string
+   */
+  public $_mode;
+
+  /**
+   * @return bool
+   */
+  public function isPayLater() {
+    return $this->isPayLater;
+  }
+
+  /**
+   * @param bool $isPayLater
+   */
+  public function setIsPayLater($isPayLater) {
+    $this->isPayLater = $isPayLater;
+  }
+
+  /**
+   * @return bool
+   */
+  public function getIsBackOffice() {
+    return $this->isBackOffice;
+  }
+
+  /**
+   * Get the payment mode ('live' or 'test')
+   *
+   * @return string
+   */
+  public function getPaymentMode() {
+    return $this->_mode;
+  }
+
+  /**
+   * Set the payment mode ('live' or 'test')
+   */
+  public function setPaymentMode() {
+    $this->_mode = ($this->_action === CRM_Core_Action::PREVIEW) ? 'test' : 'live';
+  }
+
   /**
    * @return string
    */