Merge branch 'JohnFF-patch-1'
[civicrm-core.git] / CRM / Contribute / Form / SoftCredit.php
index 53e1574f07cacb98eea5d1da468a516561897272..b8145f7898ea4cbb1cb80bfb88c582052f73e04b 100644 (file)
@@ -41,6 +41,8 @@ class CRM_Contribute_Form_SoftCredit {
   /**
    * Function to set variables up before form is built
    *
+   * @param $form
+   *
    * @return void
    * @access static
    */
@@ -74,7 +76,7 @@ class CRM_Contribute_Form_SoftCredit {
    * @return void
    */
   static function buildQuickForm(&$form) {
-    if ($form->_mode == 'live' && $form->_honor_block_is_active) {
+    if ($form->_mode == 'live' && !empty($form->_honor_block_is_active)) {
       $ufJoinDAO = new CRM_Core_DAO_UFJoin();
       $ufJoinDAO->module = 'soft_credit';
       $ufJoinDAO->entity_id = $form->_id;
@@ -86,13 +88,12 @@ class CRM_Contribute_Form_SoftCredit {
           }
 
           $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
-          $extraOption = array('onclick' => "enableHonorType();");
 
           // radio button for Honor Type
           foreach ($jsonData['soft_credit_types'] as $value) {
-            $honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value, $extraOption);
+            $honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value);
           }
-          $form->addGroup($honorTypes, 'soft_credit_type_id', NULL);
+          $form->addGroup($honorTypes, 'soft_credit_type_id', NULL)->setAttribute('allowClear', TRUE);
         }
       }
         return $form;
@@ -105,7 +106,7 @@ class CRM_Contribute_Form_SoftCredit {
     if ($form->getAction() & CRM_Core_Action::UPDATE) {
       $form->_softCreditInfo = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($form->_id, TRUE);
     }
-    elseif ($form->_pledgeID) {
+    elseif (!empty($form->_pledgeID)) {
       //Check and select most recent completed contrubtion and use it to retrieve
       //soft-credit information to use as default for current pledge payment, CRM-13981
       $pledgePayments = CRM_Pledge_BAO_PledgePayment::getPledgePayments($form->_pledgeID);
@@ -160,7 +161,10 @@ class CRM_Contribute_Form_SoftCredit {
    * Function used to set defaults for soft credit block
    */
   static function setDefaultValues(&$defaults, &$form) {
+    //Used to hide/unhide PCP and/or Soft-credit Panes
+    $noPCP = $noSoftCredit = TRUE;
     if (!empty($form->_softCreditInfo['soft_credit'])) {
+      $noSoftCredit = FALSE;
       foreach ($form->_softCreditInfo['soft_credit'] as $key => $value) {
         $defaults["soft_credit_amount[$key]"] = CRM_Utils_Money::format($value['amount'], NULL, '%a');
         $defaults["soft_credit_contact_id[$key]"] = $value['contact_id'];
@@ -168,6 +172,7 @@ class CRM_Contribute_Form_SoftCredit {
       }
     }
     if (!empty($form->_softCreditInfo['pcp_id'])) {
+      $noPCP = FALSE;
       $pcpInfo = $form->_softCreditInfo;
       $pcpId = CRM_Utils_Array::value('pcp_id', $pcpInfo);
       $pcpTitle = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcpId, 'title');
@@ -178,14 +183,20 @@ class CRM_Contribute_Form_SoftCredit {
       $defaults['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $pcpInfo);
       $defaults['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $pcpInfo);
     }
+
+    $form->assign('noSoftCredit', $noSoftCredit);
+    $form->assign('noPCP', $noPCP);
   }
 
   /**
    * global form rule
    *
-   * @param array $fields  the input form values
+   * @param array $fields the input form values
+   *
+   * @param $errors
+   * @param $self
    *
-   * @return true if no errors, else array of errors
+   * @return array of errors
    * @access public
    * @static
    */