Merge pull request #15339 from seamuslee001/hook_before_boot
[civicrm-core.git] / CRM / Pledge / Form / Pledge.php
index e7478f8b1310de74db35e4ceccccb1eca04fb1dd..3e80eb7615da505ff7ff5a7ccaa28d868a4d1852 100644 (file)
@@ -96,7 +96,6 @@ class CRM_Pledge_Form_Pledge extends CRM_Core_Form {
       list($this->userDisplayName,
         $this->userEmail
         ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
-      $this->assign('displayName', $this->userDisplayName);
     }
 
     $this->setPageTitle(ts('Pledge'));
@@ -153,6 +152,9 @@ class CRM_Pledge_Form_Pledge extends CRM_Core_Form {
       $this->assign('installments', $defaults['installments']);
     }
     else {
+      if ($this->_contactID) {
+        $defaults['contact_id'] = $this->_contactID;
+      }
       // default values.
       $defaults['create_date'] = date('Y-m-d');
       $defaults['start_date'] = date('Y-m-d');
@@ -211,11 +213,9 @@ class CRM_Pledge_Form_Pledge extends CRM_Core_Form {
       return;
     }
 
-    if ($this->_context == 'standalone') {
-      $this->addEntityRef('contact_id', ts('Contact'), [
-        'create' => TRUE,
-        'api' => ['extra' => ['email']],
-      ], TRUE);
+    $contactField = $this->addEntityRef('contact_id', ts('Contact'), ['create' => TRUE, 'api' => ['extra' => ['email']]], TRUE);
+    if ($this->_context != 'standalone') {
+      $contactField->freeze();
     }
 
     $showAdditionalInfo = FALSE;
@@ -545,12 +545,6 @@ class CRM_Pledge_Form_Pledge extends CRM_Core_Form {
       // send Acknowledgment mail.
       CRM_Pledge_BAO_Pledge::sendAcknowledgment($this, $params);
 
-      if (!isset($this->userEmail)) {
-        list($this->userDisplayName,
-          $this->userEmail
-          ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
-      }
-
       $statusMsg .= ' ' . ts("An acknowledgment email has been sent to %1.<br />", [1 => $this->userEmail]);
 
       // build the payment urls.