}
/**
- * Function to build profile form
- *
- * @params object $form form object
- * @params array $field array field properties
- * @params int $mode profile mode
- * @params int $contactID contact id
- * @params string $usedFor for building up prefixed fieldname for special cases (e.g. onBehalf, Honor)
+ * Function to add profile field to a form
*
* @param CRM_Core_Form $form
- * @param $field
- * @param $mode
- * @param null $contactId
+ * @param array $field properties
+ * @param int $mode profile mode
+ * @param int $contactId
* @param bool $online
- * @param null $usedFor
- * @param null $rowNumber
+ * @param string $usedFor for building up prefixed fieldname for special cases (e.g. onBehalf, Honor)
+ * @param int $rowNumber
* @param string $prefix
*
* @return null
$prefix = ''
) {
$defaultValues = array();
- $fieldName = $field['name'];
- $title = $field['title'];
- $attributes = $field['attributes'];
- $rule = $field['rule'];
- $view = $field['is_view'];
- $required = ($mode == CRM_Profile_Form::MODE_SEARCH) ? FALSE : $field['is_required'];
- $search = ($mode == CRM_Profile_Form::MODE_SEARCH) ? TRUE : FALSE;
- $isShared = CRM_Utils_Array::value('is_shared', $field, 0);
+ $fieldName = $field['name'];
+ $title = $field['title'];
+ $attributes = $field['attributes'];
+ $rule = $field['rule'];
+ $view = $field['is_view'];
+ $required = ($mode == CRM_Profile_Form::MODE_SEARCH) ? FALSE : $field['is_required'];
+ $search = ($mode == CRM_Profile_Form::MODE_SEARCH) ? TRUE : FALSE;
+ $isShared = CRM_Utils_Array::value('is_shared', $field, 0);
// do not display view fields in drupal registration form
// CRM-4632
$name = $fieldName;
}
+ $selectAttributes = array('class' => 'crm-select2', 'placeholder' => TRUE);
+
// CRM-15172 - keep track of all the fields we've processed
// This is hackish but we can't always rely on $form->_fields depending on how this is called
static $fieldsProcessed = array();
if (substr($fieldName, 0, 14) === 'state_province') {
$controlField = str_replace('state_province', 'country', $name);
if (isset($form->_fields[$controlField]) || in_array($controlField, $fieldsProcessed)) {
- $form->addChainSelect($name, array('label' => $title, 'required' => $required));
+ $form->addChainSelect($name, array('label' => $title, 'required' => $required));
}
else {
- $form->add('select', $name, $title,
- array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required);
+ $options = CRM_Core_PseudoConstant::stateProvince();
+ $form->add('select', $name, $title, $options, $required && $options, $selectAttributes);
}
$config = CRM_Core_Config::singleton();
if (!in_array($mode, array(
}
}
elseif (substr($fieldName, 0, 7) === 'country') {
- $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required);
+ $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required, $selectAttributes);
$config = CRM_Core_Config::singleton();
if (!in_array($mode, array(
CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) &&
}
elseif (substr($fieldName, 0, 6) === 'county') {
if ($addressOptions['county']) {
- $form->addChainSelect($name, array('label' => $title, 'required' => $required));
+ $controlField = str_replace('county', 'state_province', $name);
+ if (isset($form->_fields[$controlField]) || in_array($controlField, $fieldsProcessed)) {
+ $form->addChainSelect($name, array('label' => $title, 'required' => $required));
+ }
+ else {
+ $options = CRM_Core_PseudoConstant::county();
+ $form->add('select', $name, $title, $options, $required && $options, $selectAttributes);
+ }
}
}
elseif (substr($fieldName, 0, 9) === 'image_URL') {
}
}
elseif ($fieldName === 'prefix_id' || $fieldName === 'suffix_id') {
- $form->add('select', $name, $title,
- array(
- '' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Contact_BAO_Contact', $fieldName), $required
- );
+ $form->addSelect($name, array(
+ 'label' => $title,
+ 'entity' => 'contact',
+ 'field' => $fieldName,
+ 'class' => 'six',
+ 'placeholder' => '',
+ ), $required);
}
elseif ($fieldName === 'contact_sub_type') {
$gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
);
}
elseif ($fieldName == 'soft_credit_type') {
+ $name = "soft_credit_type[$rowNumber]";
$form->add('select', $name, $title,
array(
'' => ts('- select -')) + CRM_Core_OptionGroup::values("soft_credit_type")
);
- $form->addElement('hidden', 'sct_default_id',
- CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"),
- array('id' => 'sct_default_id')
- );
+ //CRM-15350: choose SCT field default value as 'Gift' for membership use
+ //else (for contribution), use configured SCT default value
+ $SCTDefaultValue = CRM_Core_OptionGroup::getDefaultValue("soft_credit_type");
+ if ($field['field_type'] == 'Membership') {
+ $SCTDefaultValue = CRM_Core_OptionGroup::getValue('soft_credit_type', 'Gift', 'name');
+ }
+ $form->addElement('hidden', 'sct_default_id', $SCTDefaultValue, array('id' => 'sct_default_id'));
}
elseif ($fieldName == 'currency') {
$form->addCurrency($name, $title, $required);
}
}
elseif ($fieldName == 'world_region') {
- $form->add('select', $name, $title,
- array(
- '' => ts('- select -')) + CRM_Core_PseudoConstant::worldRegion(), $required
- );
+ $form->add('select', $name, $title, CRM_Core_PseudoConstant::worldRegion(), $required, $selectAttributes);
}
elseif ($fieldName == 'signature_html') {
$form->addWysiwyg($name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName));
));
$form->add('select', $name, $title,
array(
- '' => ts('- select -')) + $campaigns, $required, 'class="big"'
+ '' => ts('- select -')) + $campaigns, $required, 'class="crm-select2 big"'
);
}
}
case 'Event':
$componentBAO = 'CRM_Event_BAO_Participant';
$componentBAOName = 'Participant';
- $componentSubType = array('role_id', 'event_id');
+ $componentSubType = array('role_id', 'event_id', 'event_type_id');
break;
case 'Activity':
//get the component values.
CRM_Core_DAO::commonRetrieve($componentBAO, $params, $values);
+ if ($componentBAOName == 'Participant') {
+ $values += array('event_type_id' => CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $values['event_id'], 'event_type_id'));
+ }
$formattedGroupTree = array();
$dateTimeFields = array('participant_register_date', 'activity_date_time', 'receive_date', 'receipt_date', 'cancel_date', 'thankyou_date', 'membership_start_date', 'membership_end_date', 'join_date');
$skipValue = FALSE;
foreach ($formattedGroupTree as $tree) {
- if ('CheckBox' == CRM_Utils_Array::value('html_type', $tree['fields'][$customFieldDetails[0]])) {
- $skipValue = TRUE;
- $defaults['field'][$componentId][$name] = $customValue;
- break;
- }
- elseif (CRM_Utils_Array::value('data_type', $tree['fields'][$customFieldDetails[0]]) == 'Date') {
- $skipValue = TRUE;
+ if (!empty($tree['fields'][$customFieldDetails[0]])) {
+ if ('CheckBox' == CRM_Utils_Array::value('html_type', $tree['fields'][$customFieldDetails[0]])) {
+ $skipValue = TRUE;
+ $defaults['field'][$componentId][$name] = $customValue;
+ break;
+ }
+ elseif (CRM_Utils_Array::value('data_type', $tree['fields'][$customFieldDetails[0]]) == 'Date') {
+ $skipValue = TRUE;
- // CRM-6681, $default contains formatted date, time values.
- $defaults[$fldName] = $customValue;
- if (!empty($defaults[$customKey . '_time'])) {
- $defaults['field'][$componentId][$name . '_time'] = $defaults[$customKey . '_time'];
+ // CRM-6681, $default contains formatted date, time values.
+ $defaults[$fldName] = $customValue;
+ if (!empty($defaults[$customKey . '_time'])) {
+ $defaults['field'][$componentId][$name . '_time'] = $defaults[$customKey . '_time'];
+ }
}
}
}
$links[] = array(
'label' => $profile['title'],
'url' => CRM_Utils_System::url('civicrm/profile/create', "reset=1&context=dialog&gid=$id",
- NULL, NULL, FALSE, NULL, FALSE) ,
+ NULL, NULL, FALSE, FALSE, TRUE) ,
'type' => ucfirst(str_replace('new_', '', $profile['name'])),
);
}