return NULL;
}
+ /**
+ * Add onbehalf/honoree profile fields and native module fields.
+ *
+ * @param int $id
+ * @param CRM_Core_Form $form
+ *
+ * @throws \CRM_Core_Exception
+ */
+ private function buildComponentForm($id, $form): void {
+ if (empty($id)) {
+ return;
+ }
+
+ $contactID = $this->getContactID();
+
+ foreach (['soft_credit', 'on_behalf'] as $module) {
+ if ($module === 'soft_credit') {
+ if (empty($form->_values['honoree_profile_id'])) {
+ continue;
+ }
+
+ if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_values['honoree_profile_id'], 'is_active')) {
+ CRM_Core_Error::statusBounce(ts('This contribution page has been configured for contribution on behalf of honoree and the selected honoree profile is either disabled or not found.'));
+ }
+
+ $profileContactType = CRM_Core_BAO_UFGroup::getContactType($form->_values['honoree_profile_id']);
+ $requiredProfileFields = [
+ 'Individual' => ['first_name', 'last_name'],
+ 'Organization' => ['organization_name', 'email'],
+ 'Household' => ['household_name', 'email'],
+ ];
+ $validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($form->_values['honoree_profile_id'], $requiredProfileFields[$profileContactType]);
+ if (!$validProfile) {
+ CRM_Core_Error::statusBounce(ts('This contribution page has been configured for contribution on behalf of honoree and the required fields of the selected honoree profile are disabled or doesn\'t exist.'));
+ }
+
+ foreach (['honor_block_title', 'honor_block_text'] as $name) {
+ $form->assign($name, $form->_values[$name]);
+ }
+
+ $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
+
+ // radio button for Honor Type
+ foreach ($form->_values['soft_credit_types'] as $value) {
+ $honorTypes[$value] = $softCreditTypes[$value];
+ }
+ $form->addRadio('soft_credit_type_id', NULL, $honorTypes, ['allowClear' => TRUE]);
+
+ $honoreeProfileFields = CRM_Core_BAO_UFGroup::getFields(
+ $this->_values['honoree_profile_id'], FALSE,
+ NULL, NULL,
+ NULL, FALSE,
+ NULL, TRUE,
+ NULL, CRM_Core_Permission::CREATE
+ );
+ $form->assign('honoreeProfileFields', $honoreeProfileFields);
+
+ // add the form elements
+ foreach ($honoreeProfileFields as $name => $field) {
+ // If soft credit type is not chosen then make omit requiredness from honoree profile fields
+ if (count($form->_submitValues) &&
+ empty($form->_submitValues['soft_credit_type_id']) &&
+ !empty($field['is_required'])
+ ) {
+ $field['is_required'] = FALSE;
+ }
+ CRM_Core_BAO_UFGroup::buildProfile($form, $field, CRM_Profile_Form::MODE_CREATE, NULL, FALSE, FALSE, NULL, 'honor');
+ }
+ }
+ else {
+ if (empty($form->_values['onbehalf_profile_id'])) {
+ continue;
+ }
+
+ if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_values['onbehalf_profile_id'], 'is_active')) {
+ CRM_Core_Error::statusBounce(ts('This contribution page has been configured for contribution on behalf of an organization and the selected onbehalf profile is either disabled or not found.'));
+ }
+
+ $member = CRM_Member_BAO_Membership::getMembershipBlock($form->_id);
+ if (empty($member['is_active'])) {
+ $msg = ts('Mixed profile not allowed for on behalf of registration/sign up.');
+ $onBehalfProfile = CRM_Core_BAO_UFGroup::profileGroups($form->_values['onbehalf_profile_id']);
+ foreach (
+ [
+ 'Individual',
+ 'Organization',
+ 'Household',
+ ] as $contactType
+ ) {
+ if (in_array($contactType, $onBehalfProfile) &&
+ (in_array('Membership', $onBehalfProfile) ||
+ in_array('Contribution', $onBehalfProfile)
+ )
+ ) {
+ CRM_Core_Error::statusBounce($msg);
+ }
+ }
+ }
+
+ if ($contactID) {
+ // retrieve all permissioned organizations of contact $contactID
+ $organizations = CRM_Contact_BAO_Relationship::getPermissionedContacts($contactID, NULL, NULL, 'Organization');
+
+ if (count($organizations)) {
+ // Related org url - pass checksum if needed
+ $args = [
+ 'ufID' => $form->_values['onbehalf_profile_id'],
+ 'cid' => '',
+ ];
+ if (!empty($_GET['cs'])) {
+ $args = [
+ 'ufID' => $form->_values['onbehalf_profile_id'],
+ 'uid' => $this->_contactID,
+ 'cs' => $_GET['cs'],
+ 'cid' => '',
+ ];
+ }
+ $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', $args, FALSE, NULL, FALSE);
+ }
+ if (count($organizations) > 0) {
+ $form->add('select', 'onbehalfof_id', '', CRM_Utils_Array::collect('name', $organizations));
+
+ $orgOptions = [
+ 0 => ts('Select an existing organization'),
+ 1 => ts('Enter a new organization'),
+ ];
+ $form->addRadio('org_option', ts('options'), $orgOptions);
+ $form->setDefaults(['org_option' => 0]);
+ }
+ }
+
+ $form->assign('fieldSetTitle', CRM_Core_BAO_UFGroup::getFrontEndTitle($form->_values['onbehalf_profile_id']));
+
+ if (!empty($form->_values['is_for_organization'])) {
+ if ($form->_values['is_for_organization'] == 2) {
+ $form->assign('onBehalfRequired', TRUE);
+ }
+ else {
+ $form->addElement('checkbox', 'is_for_organization',
+ $form->_values['for_organization'],
+ NULL
+ );
+ }
+ }
+
+ $profileFields = CRM_Core_BAO_UFGroup::getFields(
+ $form->_values['onbehalf_profile_id'],
+ FALSE, CRM_Core_Action::VIEW, NULL,
+ NULL, FALSE, NULL, FALSE, NULL,
+ CRM_Core_Permission::CREATE, NULL
+ );
+
+ if (!empty($form->_submitValues['onbehalf'])) {
+ if (!empty($form->_submitValues['onbehalfof_id'])) {
+ $form->assign('submittedOnBehalf', $form->_submitValues['onbehalfof_id']);
+ }
+ $form->assign('submittedOnBehalfInfo', json_encode(str_replace('"', '\"', $form->_submitValues['onbehalf']), JSON_HEX_APOS));
+ }
+
+ $fieldTypes = ['Contact', 'Organization'];
+ if (!empty($form->_membershipBlock)) {
+ $fieldTypes = array_merge($fieldTypes, ['Membership']);
+ }
+ $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
+ $fieldTypes = array_merge($fieldTypes, $contactSubType);
+
+ foreach ($profileFields as $name => $field) {
+ if (in_array($field['field_type'], $fieldTypes)) {
+ [$prefixName, $index] = CRM_Utils_System::explode('-', $name, 2);
+ if (in_array($prefixName, ['organization_name', 'email']) && empty($field['is_required'])) {
+ $field['is_required'] = 1;
+ }
+ if (count($form->_submitValues) &&
+ empty($form->_submitValues['is_for_organization']) &&
+ $form->_values['is_for_organization'] == 1 &&
+ !empty($field['is_required'])
+ ) {
+ $field['is_required'] = FALSE;
+ }
+ CRM_Core_BAO_UFGroup::buildProfile($form, $field, NULL, NULL, FALSE, 'onbehalf', NULL, 'onbehalf');
+ }
+ }
+ }
+ }
+ $form->assign('locDataURL', $locDataURL ?? NULL);
+ $form->assign('onBehalfOfFields', $profileFields ?? NULL);
+
+ }
+
}
}
}
- /**
- * Add onbehalf/honoree profile fields and native module fields.
- *
- * @param int $id
- * @param CRM_Core_Form $form
- *
- * @throws \CRM_Core_Exception
- */
- public function buildComponentForm($id, $form): void {
- if (empty($id)) {
- return;
- }
-
- $contactID = $this->getContactID();
-
- foreach (['soft_credit', 'on_behalf'] as $module) {
- if ($module === 'soft_credit') {
- if (empty($form->_values['honoree_profile_id'])) {
- continue;
- }
-
- if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_values['honoree_profile_id'], 'is_active')) {
- CRM_Core_Error::statusBounce(ts('This contribution page has been configured for contribution on behalf of honoree and the selected honoree profile is either disabled or not found.'));
- }
-
- $profileContactType = CRM_Core_BAO_UFGroup::getContactType($form->_values['honoree_profile_id']);
- $requiredProfileFields = [
- 'Individual' => ['first_name', 'last_name'],
- 'Organization' => ['organization_name', 'email'],
- 'Household' => ['household_name', 'email'],
- ];
- $validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($form->_values['honoree_profile_id'], $requiredProfileFields[$profileContactType]);
- if (!$validProfile) {
- CRM_Core_Error::statusBounce(ts('This contribution page has been configured for contribution on behalf of honoree and the required fields of the selected honoree profile are disabled or doesn\'t exist.'));
- }
-
- foreach (['honor_block_title', 'honor_block_text'] as $name) {
- $form->assign($name, $form->_values[$name]);
- }
-
- $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
-
- // radio button for Honor Type
- foreach ($form->_values['soft_credit_types'] as $value) {
- $honorTypes[$value] = $softCreditTypes[$value];
- }
- $form->addRadio('soft_credit_type_id', NULL, $honorTypes, ['allowClear' => TRUE]);
-
- $honoreeProfileFields = CRM_Core_BAO_UFGroup::getFields(
- $this->_values['honoree_profile_id'], FALSE,
- NULL, NULL,
- NULL, FALSE,
- NULL, TRUE,
- NULL, CRM_Core_Permission::CREATE
- );
- $form->assign('honoreeProfileFields', $honoreeProfileFields);
-
- // add the form elements
- foreach ($honoreeProfileFields as $name => $field) {
- // If soft credit type is not chosen then make omit requiredness from honoree profile fields
- if (count($form->_submitValues) &&
- empty($form->_submitValues['soft_credit_type_id']) &&
- !empty($field['is_required'])
- ) {
- $field['is_required'] = FALSE;
- }
- CRM_Core_BAO_UFGroup::buildProfile($form, $field, CRM_Profile_Form::MODE_CREATE, NULL, FALSE, FALSE, NULL, 'honor');
- }
- }
- else {
- if (empty($form->_values['onbehalf_profile_id'])) {
- continue;
- }
-
- if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_values['onbehalf_profile_id'], 'is_active')) {
- CRM_Core_Error::statusBounce(ts('This contribution page has been configured for contribution on behalf of an organization and the selected onbehalf profile is either disabled or not found.'));
- }
-
- $member = CRM_Member_BAO_Membership::getMembershipBlock($form->_id);
- if (empty($member['is_active'])) {
- $msg = ts('Mixed profile not allowed for on behalf of registration/sign up.');
- $onBehalfProfile = CRM_Core_BAO_UFGroup::profileGroups($form->_values['onbehalf_profile_id']);
- foreach (
- [
- 'Individual',
- 'Organization',
- 'Household',
- ] as $contactType
- ) {
- if (in_array($contactType, $onBehalfProfile) &&
- (in_array('Membership', $onBehalfProfile) ||
- in_array('Contribution', $onBehalfProfile)
- )
- ) {
- CRM_Core_Error::statusBounce($msg);
- }
- }
- }
-
- if ($contactID) {
- // retrieve all permissioned organizations of contact $contactID
- $organizations = CRM_Contact_BAO_Relationship::getPermissionedContacts($contactID, NULL, NULL, 'Organization');
-
- if (count($organizations)) {
- // Related org url - pass checksum if needed
- $args = [
- 'ufID' => $form->_values['onbehalf_profile_id'],
- 'cid' => '',
- ];
- if (!empty($_GET['cs'])) {
- $args = [
- 'ufID' => $form->_values['onbehalf_profile_id'],
- 'uid' => $this->_contactID,
- 'cs' => $_GET['cs'],
- 'cid' => '',
- ];
- }
- $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', $args, FALSE, NULL, FALSE);
- }
- if (count($organizations) > 0) {
- $form->add('select', 'onbehalfof_id', '', CRM_Utils_Array::collect('name', $organizations));
-
- $orgOptions = [
- 0 => ts('Select an existing organization'),
- 1 => ts('Enter a new organization'),
- ];
- $form->addRadio('org_option', ts('options'), $orgOptions);
- $form->setDefaults(['org_option' => 0]);
- }
- }
-
- $form->assign('fieldSetTitle', CRM_Core_BAO_UFGroup::getFrontEndTitle($form->_values['onbehalf_profile_id']));
-
- if (!empty($form->_values['is_for_organization'])) {
- if ($form->_values['is_for_organization'] == 2) {
- $form->assign('onBehalfRequired', TRUE);
- }
- else {
- $form->addElement('checkbox', 'is_for_organization',
- $form->_values['for_organization'],
- NULL
- );
- }
- }
-
- $profileFields = CRM_Core_BAO_UFGroup::getFields(
- $form->_values['onbehalf_profile_id'],
- FALSE, CRM_Core_Action::VIEW, NULL,
- NULL, FALSE, NULL, FALSE, NULL,
- CRM_Core_Permission::CREATE, NULL
- );
-
- if (!empty($form->_submitValues['onbehalf'])) {
- if (!empty($form->_submitValues['onbehalfof_id'])) {
- $form->assign('submittedOnBehalf', $form->_submitValues['onbehalfof_id']);
- }
- $form->assign('submittedOnBehalfInfo', json_encode(str_replace('"', '\"', $form->_submitValues['onbehalf']), JSON_HEX_APOS));
- }
-
- $fieldTypes = ['Contact', 'Organization'];
- if (!empty($form->_membershipBlock)) {
- $fieldTypes = array_merge($fieldTypes, ['Membership']);
- }
- $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
- $fieldTypes = array_merge($fieldTypes, $contactSubType);
-
- foreach ($profileFields as $name => $field) {
- if (in_array($field['field_type'], $fieldTypes)) {
- [$prefixName, $index] = CRM_Utils_System::explode('-', $name, 2);
- if (in_array($prefixName, ['organization_name', 'email']) && empty($field['is_required'])) {
- $field['is_required'] = 1;
- }
- if (count($form->_submitValues) &&
- empty($form->_submitValues['is_for_organization']) &&
- $form->_values['is_for_organization'] == 1 &&
- !empty($field['is_required'])
- ) {
- $field['is_required'] = FALSE;
- }
- CRM_Core_BAO_UFGroup::buildProfile($form, $field, NULL, NULL, FALSE, 'onbehalf', NULL, 'onbehalf');
- }
- }
- }
- }
- $form->assign('locDataURL', $locDataURL ?? NULL);
- $form->assign('onBehalfOfFields', $profileFields ?? NULL);
-
- }
-
/**
* Check template file exists.
*