CRM-17227: Error thrown while saving profile in Contribution page
authoryashodha <yashodha.chaku@webaccessglobal.com>
Wed, 16 Sep 2015 10:53:44 +0000 (16:23 +0530)
committeryashodha <yashodha.chaku@webaccessglobal.com>
Wed, 16 Sep 2015 10:53:44 +0000 (16:23 +0530)
----------------------------------------
* CRM-17227: Error thrown while saving profile in Contribution page
  https://issues.civicrm.org/jira/browse/CRM-17227

CRM/Contribute/Form/ContributionPage.php
CRM/Contribute/Form/ContributionPage/Custom.php

index 09889fd4538c6346ccf066d2192f312484d3607e..9860752e1dc70f3d21d8f86791f09d3b421c3c11 100644 (file)
@@ -136,6 +136,7 @@ class CRM_Contribute_Form_ContributionPage extends CRM_Core_Form {
       if (isset($this->_id) && $this->_id) {
         $params = array('id' => $this->_id);
         CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $this->_values);
+        CRM_Contribute_BAO_ContributionPage::setValues($this->_id, $this->_values);
       }
       $this->set('values', $this->_values);
     }
index 36c6bd495267c0c4b70f0cd30afbcd5445afb632..54c8c175b76e5ea75c72fd744d31e3d1393ed1c9 100644 (file)
@@ -73,7 +73,7 @@ class CRM_Contribute_Form_ContributionPage_Custom extends CRM_Contribute_Form_Co
     $this->addProfileSelector('custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $entities, TRUE);
     $this->addProfileSelector('custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $entities, TRUE);
 
-    $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Custom', 'formRule'), $this->_id);
+    $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Custom', 'formRule'), $this);
 
     parent::buildQuickForm();
   }
@@ -86,14 +86,8 @@ class CRM_Contribute_Form_ContributionPage_Custom extends CRM_Contribute_Form_Co
   public function setDefaultValues() {
     $defaults = parent::setDefaultValues();
 
-    $ufJoinParams = array(
-      'module' => 'CiviContribute',
-      'entity_table' => 'civicrm_contribution_page',
-      'entity_id' => $this->_id,
-    );
-    list($defaults['custom_pre_id'],
-      $second) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
-    $defaults['custom_post_id'] = $second ? array_shift($second) : '';
+    $defaults['custom_pre_id'] = $this->_values['custom_pre_id'];
+    $defaults['custom_post_id'] = $this->_values['custom_post_id'];
 
     return $defaults;
   }
@@ -156,19 +150,19 @@ class CRM_Contribute_Form_ContributionPage_Custom extends CRM_Contribute_Form_Co
    *   The input form values.
    *
    * @param $files
-   * @param int $contributionPageId
+   * @param object $form
    *
    * @return bool|array
    *   true if no errors, else array of errors
    */
-  public static function formRule($fields, $files, $contributionPageId) {
+  public static function formRule($fields, $files, $form) {
     $errors = array();
     $preProfileType = $postProfileType = NULL;
     // for membership profile make sure Membership section is enabled
     // get membership section for this contribution page
     $dao = new CRM_Member_DAO_MembershipBlock();
     $dao->entity_table = 'civicrm_contribution_page';
-    $dao->entity_id = $contributionPageId;
+    $dao->entity_id = $form->_id;
 
     $membershipEnable = FALSE;
 
@@ -194,7 +188,7 @@ class CRM_Contribute_Form_ContributionPage_Custom extends CRM_Contribute_Form_Co
       $errors['custom_post_id'] = $errorMsg;
     }
 
-    $behalf = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageId, 'is_for_organization');
+    $behalf = (!empty($form->_values['onbehalf_profile_id'])) ? $form->_values['onbehalf_profile_id'] : NULL;
     if ($fields['custom_pre_id']) {
       $errorMsg = ts('You should move the membership related fields in the "On Behalf" profile for this Contribution Page');
       if ($preProfileType == 'Membership' && $behalf) {