}
$this->set('values', $this->_values);
}
+
+ // Preload libraries required by the "Profiles" tab
+ $schemas = array('IndividualModel', 'ContributionModel');
+ if (in_array('CiviMember', CRM_Core_Config::singleton()->enableComponents)) {
+ $schemas[] = 'MembershipModel';
+ }
+ CRM_UF_Page_ProfileEditor::registerProfileScripts();
+ CRM_UF_Page_ProfileEditor::registerSchemas($schemas);
}
/**
* @access public
*/
public function buildQuickForm() {
- $types = array_merge(array('Contact', 'Individual', 'Contribution', 'Membership'),
- CRM_Contact_BAO_ContactType::subTypes('Individual')
- );
-
- $profiles = CRM_Core_BAO_UFGroup::getProfiles($types);
- $excludeTypes = array('Organization', 'Household', 'Participant', 'Activity');
-
- $excludeProfiles = CRM_Core_BAO_UFGroup::getProfiles($excludeTypes);
- foreach ($excludeProfiles as $key => $value) {
- if (array_key_exists( $key, $profiles)) {
- unset($profiles[$key]);
- }
- }
- if (empty($profiles)) {
- $this->assign('noProfile', TRUE);
+ // Register 'contact_1'
+ $entities = array();
+ $entities[] = array('entity_name' => 'contact_1', 'entity_type' => 'IndividualModel');
+ $allowCoreTypes = array_merge(array('Contact', 'Individual'), CRM_Contact_BAO_ContactType::subTypes('Individual'));
+ $allowSubTypes = array();
+
+ // Register 'contribution_1'
+ $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'financial_type_id');
+ $allowCoreTypes[] = 'Contribution';
+ // $allowSubTypes['ContributionType'] = array($financialTypeId);
+ $entities[] = array('entity_name' => 'contribution_1', 'entity_type' => 'ContributionModel', 'entity_sub_type' => $financialTypeId);
+
+ // If applicable, register 'membership_1'
+ $member = CRM_Member_BAO_Membership::getMembershipBlock($this->_id);
+ if ($member && $member['is_active']) {
+ $entities[] = array('entity_name' => 'membership_1', 'entity_type' => 'MembershipModel', 'entity_sub_type' => $member['membership_type_default']);
+ $allowCoreTypes[] = 'Membership';
+ $allowSubTypes['MembershipType'] = explode(',', $member['membership_types']);
}
- $this->add('select', 'custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), array('' => ts('- select -')) + $profiles);
- $this->add('select', 'custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), array('' => ts('- select -')) + $profiles);
+ $this->addProfileSelector('custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $entities);
+ $this->addProfileSelector('custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $entities);
$this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Custom', 'formRule'), $this->_id);
'entity_id' => $this->_id,
);
list($defaults['custom_pre_id'],
- $defaults['custom_post_id']
- ) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
+ $second) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
+ $defaults['custom_post_id'] = $second ? array_shift($second) : '';
+
return $defaults;
}
$('.crm-profile-selector').each(function(){
$(this).crmProfileSelector({
groupTypeFilter: $(this).attr('data-group-type'),
- entities: eval('(' + $(this).attr('data-entities') + ')')
+ entities: $(this).data('entities')
});
});
};
*}
<div class="crm-block crm-form-block crm-contribution-contributionpage-custom-form-block">
<div id="help">
- <p>{ts}You may want to collect information from contributors beyond what is required to make a contribution. For example, you may want to inquire about volunteer availability and skills. Add any number of fields to your contribution form by selecting CiviCRM Profiles (collections of fields) to include at the beginning of the page, and/or at the bottom.{/ts}</p>
-
- {capture assign=crmURL}{crmURL p='civicrm/admin/uf/group' q="reset=1&action=browse"}{/capture}
- {if $noProfile}
- <div class="status message">
- {ts 1=$crmURL 2=Profile}No Profile(s) have been configured / enabled for your site. You need to first configure <a href="%1"><strong>» %2</a>(s).{/ts} {docURL page="user/the-user-interface/profiles"}
- </div>
- {else}
- <p>{ts 1=$crmURL}You can use existing CiviCRM Profiles on your page - OR create profile(s) specifically for use in Online Contribution pages. Go to <a href='%1'>Administer CiviCRM Profiles</a> if you need to review, modify or create profiles (you can come back at any time to select or update the Profile(s) used for this page).{/ts}</p>
- {/if}
+ <p>{ts}You may want to collect information from contributors beyond what is required to make a contribution. For example, you may want to inquire about volunteer availability and skills. Add any number of fields to your contribution form by selecting CiviCRM Profiles (collections of fields) to include at the beginning of the page, and/or at the bottom.{/ts} {help id="contrib-profile"}</p>
</div>
-{if ! $noProfile}
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
<table class="form-layout-compressed">
<tr class="crm-contribution-contributionpage-custom-form-block-custom_pre_id">
<td class="label">{$form.custom_pre_id.label}
</td>
- <td class="html-adjust">{$form.custom_pre_id.html} <span class="profile-links"></span><br />
- <span class="description">{ts}Include additional fields in this online contribution page by configuring and selecting a CiviCRM Profile to be included above the billing information (but after the introductory message, amounts, and honoree section).{/ts}{help id="contrib-profile"}</span>
+ <td class="html-adjust">{$form.custom_pre_id.html}
+ <span class="description">{ts}Profile to be included above the billing information (but after the introductory message, amounts, and honoree section).{/ts}</span>
</td>
</tr>
<tr class="crm-contribution-contributionpage-custom-form-block-custom_post_id">
<td class="label">{$form.custom_post_id.label}
</td>
- <td class="html-adjust">{$form.custom_post_id.html} <span class="profile-links"></span><br/>
- <span class="description">{ts}Include additional fields in this online contribution page by configuring and selecting a CiviCRM Profile to be included at the bottom of the page.{/ts}</span>
+ <td class="html-adjust">{$form.custom_post_id.html}
+ <span class="description">{ts}Profile to be included at the bottom of the page.{/ts}</span>
</td>
</tr>
- <tr class='crm-contribution-contributionpage-custom-form--block-create-new-profile'>
- <td class="label"></td>
- <td><a href="{crmURL p='civicrm/admin/uf/group/add' q='reset=1&action=add'}" target="_blank">{ts}Click here for new profile{/ts}</td>
- </tr>
</table>
-{/if}
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
</div>
-
-{*include profile link function*}
-{include file="CRM/common/buildProfileLink.tpl"}
-
-{literal}
-<script type="text/javascript">
- //show edit profile field links
- cj(function() {
- // show edit for profile
- cj('select[id^="custom_p"]').change( function( ) {
- buildLinks( cj(this), cj(this).val());
- });
-
- // make sure we set edit links for profile when form loads
- cj('select[id^="custom_p"]').each( function(e) {
- buildLinks( cj(this), cj(this).val());
- });
- });
-</script>
-{/literal}
-
-{* include jscript to warn if unsaved form field changes *}
-{include file="CRM/common/formNavigate.tpl"}