Ensure onBehalfEmail always assigned to prevent notices
authorEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 29 Nov 2023 12:22:25 +0000 (01:22 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 29 Nov 2023 12:22:25 +0000 (01:22 +1300)
CRM/Contribute/Form/ContributionBase.php

index 9dff9a23622e61008f23b271c427e31164a1d486..4a37189126b57b83b490d983fa11cff066b46973 100644 (file)
@@ -761,11 +761,13 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
 
     $this->assign('address', CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters($this->_params));
 
-    if (!empty($this->_params['onbehalf_profile_id']) && !empty($this->_params['onbehalf'])) {
+    $isDisplayOnBehalf = !empty($this->_params['onbehalf_profile_id']) && !empty($this->_params['onbehalf']);
+    if ($isDisplayOnBehalf) {
       $this->assign('onBehalfName', $this->_params['organization_name']);
       $locTypeId = array_keys($this->_params['onbehalf_location']['email']);
-      $this->assign('onBehalfEmail', $this->_params['onbehalf_location']['email'][$locTypeId[0]]['email']);
+      $onBehalfEmail = $this->_params['onbehalf_location']['email'][$locTypeId[0]]['email'] ?? NULL;
     }
+    $this->assign('onBehalfEmail', $onBehalfEmail ?? NULL);
     $this->assignPaymentFields();
     $this->assignEmailField();
     $this->assign('emailExists', $this->_emailExists);