manual merge of fixes for CRM-13981
[civicrm-core.git] / CRM / Contribute / Form / ContributionPage / Settings.php
index 876952da2410d9334fe4aff4c0e5f9eee6ae991d..46219b0bc9fe9d33b799b72de09394462414bba8 100644 (file)
@@ -54,6 +54,7 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_
    */
   function setDefaultValues() {
     $defaults = parent::setDefaultValues();
+    $soft_credit_types = CRM_Core_OptionGroup::values('soft_credit_type', TRUE, FALSE, FALSE, NULL, 'name');
 
     if ($this->_id) {
       $title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage',
@@ -87,13 +88,30 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_
           }
         }
       }
+      else {
+        $ufGroupDAO = new CRM_Core_DAO_UFGroup();
+        $ufGroupDAO->name = 'honoree_individual';
+        if ($ufGroupDAO->find(TRUE)) {
+          $defaults['honoree_profile'] = $ufGroupDAO->id;
+        }
+        $defaults['soft_credit_types'] = array(
+          CRM_Utils_Array::value('in_honor_of', $soft_credit_types),
+          CRM_Utils_Array::value('in_memory_of', $soft_credit_types)
+        );
+      }
     }
     else {
       CRM_Utils_System::setTitle(ts('Title and Settings'));
-    }
 
-    if (!CRM_Utils_Array::value('soft_credit_types', $defaults)) {
-      $defaults['soft_credit_types'] = array(1, 2);
+      $ufGroupDAO = new CRM_Core_DAO_UFGroup();
+      $ufGroupDAO->name = 'honoree_individual';
+      if ($ufGroupDAO->find(TRUE)) {
+        $defaults['honoree_profile'] = $ufGroupDAO->id;
+      }
+      $defaults['soft_credit_types'] = array(
+        CRM_Utils_Array::value('in_honor_of', $soft_credit_types),
+        CRM_Utils_Array::value('in_memory_of', $soft_credit_types)
+      );
     }
 
     return $defaults;
@@ -205,9 +223,6 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_
 
     $entities = array(
       array('entity_name' => 'contact_1',
-        'entity_type' => 'ContactModel'
-      ),
-      array('entity_name' => 'individual_1',
         'entity_type' => 'IndividualModel'
       ),
       array('entity_name' => 'organization_1',
@@ -222,7 +237,7 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_
 
     $this->addProfileSelector('honoree_profile', ts('Honoree Profile'), $allowCoreTypes, $allowSubTypes, $entities);
 
-    if (CRM_Utils_Array::value('honor_block_is_active', $this->_submitValues)) {
+    if (!empty($this->_submitValues['honor_block_is_active'])) {
       $this->addRule('soft_credit_types', ts('At least one value must be selected if Honor Section is active'), 'required');
       $this->addRule('honoree_profile', ts('Please select a profile used for honoree'), 'required');
     }
@@ -253,9 +268,7 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_
       $errors['title'] = ts("Please do not use '/' in Title");
     }
 
-    if (CRM_Utils_Array::value('is_organization', $values) &&
-      !CRM_Utils_Array::value('onbehalf_profile_id', $values)
-    ) {
+    if (!empty($values['is_organization']) && empty($values['onbehalf_profile_id'])) {
       $errors['onbehalf_profile_id'] = ts('Please select a profile to collect organization information on this contribution page.');
     }
 
@@ -266,14 +279,13 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_
       $errors['end_date'] = ts('End date should be after Start date.');
     }
 
-    if (CRM_Utils_Array::value('payment_processor', $self->_values)
-      && $financialType = CRM_Contribute_BAO_Contribution::validateFinancialType($values['financial_type_id'])) {
+    if (!empty($self->_values['payment_processor']) && $financialType = CRM_Contribute_BAO_Contribution::validateFinancialType($values['financial_type_id'])) {
       $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType;
     }
 
     //dont allow on behalf of save when
     //pre or post profile consists of membership fields
-    if ($contributionPageId && CRM_Utils_Array::value('is_organization', $values)) {
+    if ($contributionPageId && !empty($values['is_organization'])) {
       $ufJoinParams = array(
         'module' => 'CiviContribute',
         'entity_table' => 'civicrm_contribution_page',
@@ -332,7 +344,7 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
     $params['is_credit_card_only'] = CRM_Utils_Array::value('is_credit_card_only', $params, FALSE);
     $params['honor_block_is_active'] = CRM_Utils_Array::value('honor_block_is_active', $params, FALSE);
-    $params['is_for_organization'] = CRM_Utils_Array::value('is_organization', $params) ? CRM_Utils_Array::value('is_for_organization', $params, FALSE) : 0;
+    $params['is_for_organization'] = !empty($params['is_organization']) ? CRM_Utils_Array::value('is_for_organization', $params, FALSE) : 0;
 
     $params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time'], TRUE);
     $params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], $params['end_date_time'], TRUE);
@@ -374,7 +386,7 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_
 
 
     foreach ($ufJoinParams as $index => $ufJoinParam) {
-      if (CRM_Utils_Array::value($index, $params)) {
+      if (!empty($params[$index])) {
           $ufJoinParam['weight'] = 1;
           if ($index == 'honor_block_is_active') {
             $ufJoinParam['is_active'] = 1;