* @params int $contactID contact id
* @params string $usedFor for building up prefixed fieldname for special cases (e.g. onBehalf, Honor)
*
- * @param $form
+ * @param CRM_Core_Form $form
* @param $field
* @param $mode
* @param null $contactId
$name = $fieldName;
}
+ // 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();
+ $fieldsProcessed[] = $name;
+
if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) {
$deleteExtra = ts('Are you sure you want to delete contact image.');
$deleteURL = array(
);
if (substr($fieldName, 0, 14) === 'state_province') {
- $form->add('select', $name, $title,
- array(
- '' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required
- );
+ $controlField = str_replace('state_province', 'country', $name);
+ if (isset($form->_fields[$controlField]) || in_array($controlField, $fieldsProcessed)) {
+ $form->addChainSelect($name, array('label' => $title, 'required' => $required));
+ }
+ else {
+ $form->add('select', $name, $title,
+ array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required);
+ }
$config = CRM_Core_Config::singleton();
if (!in_array($mode, array(
CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) &&
}
}
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);
$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->add('select', $name, $title,
- array('' => ts('Choose state first')), $required
- );
+ $form->addChainSelect($name, array('label' => $title, 'required' => $required));
}
}
elseif (substr($fieldName, 0, 9) === 'image_URL') {
'non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) {
$form->addRule($name, ts('Please enter a valid amount.'), 'money');
}
- $stateCountryMap = array();
- if (!empty($form->_stateCountryMap['state_province']) && !empty($form->_stateCountryMap['country'])) {
- foreach ($form->_stateCountryMap['state_province'] as $key => $value) {
- $stateCountryMap[$key]['state_province'] = $value;
- $stateCountryMap[$key]['country'] = $form->_stateCountryMap['country'][$key];
- }
- CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
- }
if ($rule) {
if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) {
$form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule);