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';
</div>
{/if}
- {if !empty($extends) && $extends eq "Membership" && $element.name == 'membership_amount'}
- <div id="allow_auto_renew">
- <div class='crm-section auto-renew'>
- <div class='label'></div>
- <div class ='content'>
- {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')}
+ <div id="allow_auto_renew">
+ <div class='crm-section auto-renew'>
+ <div class='label'></div>
+ <div class ='content'>
+ {if isset($form.auto_renew) }
+ {$form.auto_renew.html} {$form.auto_renew.label}
+ {/if}
+ </div>
</div>
</div>
- </div>
+ {/if}
{/if}
<div class="clear"></div>
</div>