* @param bool $viewOnly
*/
public function buildCustom($id, $name, $viewOnly = FALSE) {
- if ($id) {
- $button = substr($this->controller->getButtonName(), -4);
- $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
- $session = CRM_Core_Session::singleton();
- $contactID = $session->get('userID');
-
- // we don't allow conflicting fields to be
- // configured via profile
- $fieldsToIgnore = [
- 'participant_fee_amount' => 1,
- 'participant_fee_level' => 1,
- ];
- if ($contactID) {
- //FIX CRM-9653
- if (is_array($id)) {
- $fields = [];
- foreach ($id as $profileID) {
- $field = CRM_Core_BAO_UFGroup::getFields($profileID, FALSE, CRM_Core_Action::ADD,
- NULL, NULL, FALSE, NULL,
- FALSE, NULL, CRM_Core_Permission::CREATE,
- 'field_name', TRUE
- );
- $fields = array_merge($fields, $field);
- }
- }
- else {
- if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
- $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD,
- NULL, NULL, FALSE, NULL,
- FALSE, NULL, CRM_Core_Permission::CREATE,
- 'field_name', TRUE
- );
- }
+ if (!$id) {
+ return;
+ }
+
+ $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
+ $contactID = CRM_Core_Session::getLoggedInContactID();
+
+ // we don't allow conflicting fields to be
+ // configured via profile
+ $fieldsToIgnore = [
+ 'participant_fee_amount' => 1,
+ 'participant_fee_level' => 1,
+ ];
+ if ($contactID) {
+ //FIX CRM-9653
+ if (is_array($id)) {
+ $fields = [];
+ foreach ($id as $profileID) {
+ $field = CRM_Core_BAO_UFGroup::getFields($profileID, FALSE, CRM_Core_Action::ADD,
+ NULL, NULL, FALSE, NULL,
+ FALSE, NULL, CRM_Core_Permission::CREATE,
+ 'field_name', TRUE
+ );
+ $fields = array_merge($fields, $field);
}
}
else {
- $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD,
- NULL, NULL, FALSE, NULL,
- FALSE, NULL, CRM_Core_Permission::CREATE,
- 'field_name', TRUE
- );
- }
-
- if (array_intersect_key($fields, $fieldsToIgnore)) {
- $fields = array_diff_key($fields, $fieldsToIgnore);
- CRM_Core_Session::setStatus(ts('Some of the profile fields cannot be configured for this page.'));
+ if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
+ $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD,
+ NULL, NULL, FALSE, NULL,
+ FALSE, NULL, CRM_Core_Permission::CREATE,
+ 'field_name', TRUE
+ );
+ }
}
- $addCaptcha = FALSE;
+ }
+ else {
+ $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD,
+ NULL, NULL, FALSE, NULL,
+ FALSE, NULL, CRM_Core_Permission::CREATE,
+ 'field_name', TRUE
+ );
+ }
- if (!empty($this->_fields)) {
- $fields = @array_diff_assoc($fields, $this->_fields);
- }
+ if (array_intersect_key($fields, $fieldsToIgnore)) {
+ $fields = array_diff_key($fields, $fieldsToIgnore);
+ CRM_Core_Session::setStatus(ts('Some of the profile fields cannot be configured for this page.'));
+ }
+ $addCaptcha = FALSE;
- if (empty($this->_params[0]['additional_participants']) &&
- is_null($cid)
- ) {
- CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID);
- }
- $this->assign($name, $fields);
- if (is_array($fields)) {
- foreach ($fields as $key => $field) {
- if ($viewOnly &&
- isset($field['data_type']) &&
- $field['data_type'] == 'File' || ($viewOnly && $field['name'] == 'image_URL')
- ) {
- // ignore file upload fields
- continue;
- }
- //make the field optional if primary participant
- //have been skip the additional participant.
- if ($button == 'skip') {
- $field['is_required'] = FALSE;
- }
- // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
- elseif ($field['add_captcha'] && !$contactID) {
- // only add captcha for first page
- $addCaptcha = TRUE;
- }
- list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
- CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
+ if (!empty($this->_fields)) {
+ $fields = @array_diff_assoc($fields, $this->_fields);
+ }
- $this->_fields[$key] = $field;
+ if (empty($this->_params[0]['additional_participants']) &&
+ is_null($cid)
+ ) {
+ CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID);
+ }
+ $this->assign($name, $fields);
+ if (is_array($fields)) {
+ $button = substr($this->controller->getButtonName(), -4);
+ foreach ($fields as $key => $field) {
+ if ($viewOnly &&
+ isset($field['data_type']) &&
+ $field['data_type'] == 'File' || ($viewOnly && $field['name'] == 'image_URL')
+ ) {
+ // ignore file upload fields
+ continue;
}
- }
+ //make the field optional if primary participant
+ //have been skip the additional participant.
+ if ($button == 'skip') {
+ $field['is_required'] = FALSE;
+ }
+ // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
+ elseif ($field['add_captcha'] && !$contactID) {
+ // only add captcha for first page
+ $addCaptcha = TRUE;
+ }
+ CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
- if ($addCaptcha && !$viewOnly) {
- CRM_Utils_ReCAPTCHA::enableCaptchaOnForm($this);
+ $this->_fields[$key] = $field;
}
}
+
+ if ($addCaptcha && !$viewOnly) {
+ CRM_Utils_ReCAPTCHA::enableCaptchaOnForm($this);
+ }
}
/**