From: Allen Shaw Date: Thu, 31 Mar 2016 21:19:21 +0000 (-0500) Subject: CRM-18305 - CiviMember - Auto-renew checkbox option was being displayed multiple... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ee7f71d951b34be81544ea543f909aa8c2dca2df;p=civicrm-core.git CRM-18305 - CiviMember - Auto-renew checkbox option was being displayed multiple times. With support for contribution pages with and without price sets. --- diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index 67c8ab4dc9..c9a485a653 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -1056,6 +1056,29 @@ WHERE id = %1"; if ($className == 'CRM_Contribute_Form_Contribution_Main') { $form->_quickConfig = $quickConfig; } + + // Mark which field should have the auto-renew checkbox, if any. CRM-18305 + if (is_array($form->_membershipTypeValues)) { + $autoRenewMembershipTypes = array(); + foreach ($form->_membershipTypeValues as $membershiptTypeValue) { + if ($membershiptTypeValue['auto_renew']) { + $autoRenewMembershipTypes[] = $membershiptTypeValue['id']; + } + } + foreach ($form->_priceSet['fields'] as &$field) { + if (array_key_exists('options', $field) && is_array($field['options'])) { + foreach ($field['options'] as $option) { + if ($option['membership_type_id']) { + if (in_array($option['membership_type_id'], $autoRenewMembershipTypes)) { + $form->_priceSet['auto_renew_membership_field'] = $field['id']; + // Only one field can offer auto_renew memberships, so break here. + break; + } + } + } + } + } + } $form->assign('priceSet', $form->_priceSet); $component = 'contribution'; diff --git a/templates/CRM/Price/Form/PriceSet.tpl b/templates/CRM/Price/Form/PriceSet.tpl index 86a70d95d9..e717726749 100644 --- a/templates/CRM/Price/Form/PriceSet.tpl +++ b/templates/CRM/Price/Form/PriceSet.tpl @@ -102,17 +102,19 @@ {/if} - {if !empty($extends) && $extends eq "Membership" && $element.name == 'membership_amount'} -
-
-
-
- {if isset($form.auto_renew) } - {$form.auto_renew.html} {$form.auto_renew.label} - {/if} + {if !empty($extends) && $extends eq "Membership"} + {if (!empty($priceSet) && $element.id == $priceSet.auto_renew_membership_field) || (empty($priceSet) && $element.name == 'membership_amount')} +
+
+
+
+ {if isset($form.auto_renew) } + {$form.auto_renew.html} {$form.auto_renew.label} + {/if} +
-
+ {/if} {/if}