$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
if ($this->_gid) {
$this->_title = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'title');
- CRM_Utils_System::setTitle($this->_title . ' - ' . ts('CiviCRM Profile Fields'));
+
+ $this->setPageTitle(ts('Profile Field'));
$url = CRM_Utils_System::url('civicrm/admin/uf/group/field',
"reset=1&action=browse&gid={$this->_gid}"
$defaults['field_name'] = array(
$defaults['field_type'],
($defaults['field_type'] == "Formatting" ? "" : $defaults['field_name']),
- $defaults['location_type_id'],
+ ($defaults['field_name'] == "url") ? $defaults['website_type_id'] : $defaults['location_type_id'],
CRM_Utils_Array::value('phone_type_id', $defaults),
);
$this->_gid = $defaults['uf_group_id'];
$fields = CRM_Core_BAO_UFField::getAvailableFields($this->_gid, $defaults);
- $noSearchable = array();
+ $noSearchable = $hasWebsiteTypes = array();
$addressCustomFields = array_keys(CRM_Core_BAO_CustomField::getFieldsForImport('Address'));
foreach ($fields as $key => $value) {
$this->_mapperFields[$key][$key1] = $value1['title'];
}
$hasLocationTypes[$key][$key1] = CRM_Utils_Array::value('hasLocationType', $value1);
-
+ $hasWebsiteTypes[$key][$key1] = CRM_Utils_Array::value('hasWebsiteType', $value1);
// hide the 'is searchable' field for 'File' custom data
if (isset($value1['data_type']) &&
isset($value1['html_type']) &&
$this->_location_types = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
$defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
+ $this->_website_types = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id');
/**
* FIXME: dirty hack to make the default option show up first. This
if ($hasLocationTypes[$k][$key]) {
$sel3[$k][$key] = $this->_location_types;
}
+ elseif ($hasWebsiteTypes[$k][$key]) {
+ $sel3[$k][$key] = $this->_website_types;
+ }
else {
$sel3[$key] = NULL;
}
if (empty($formValues)) {
for ($k = 1; $k < 4; $k++) {
- if (!$defaults['field_name'][$k]) {
+ if (!isset($defaults['field_name'][$k])) {
$js .= "{$formName}['field_name[$k]'].style.display = 'none';\n";
}
}
}
else {
if (!empty($formValues['field_name'])) {
- foreach ($formValues['field_name'] as $value) {
- for ($k = 1; $k < 4; $k++) {
- if (!isset($formValues['field_name'][$k]) || !$formValues['field_name'][$k]) {
- $js .= "{$formName}['field_name[$k]'].style.display = 'none';\n";
- }
- else {
- $js .= "{$formName}['field_name[$k]'].style.display = '';\n";
- }
+ for ($key = 1; $key < 4; $key++) {
+ if (!isset($formValues['field_name'][$key])) {
+ $js .= "{$formName}['field_name[$key]'].style.display = 'none';\n";
+ }
+ else {
+ $js .= "{$formName}['field_name[$key]'].style.display = '';\n";
}
}
}
);
}
- if (isset($defaults['field_name']) && CRM_Utils_Array::value(1, $defaults['field_name']) == 'url-1') {
- $defaults['field_name'][1] = 'url';
- }
-
$this->setDefaults($defaults);
}
$params['field_name'][1] = 'formatting_' . rand(1000, 9999);
}
- // temporary hack to for website
- if ($params['field_name'][1] == 'url') {
- $params['field_name'][1] = 'url-1';
- }
-
//check for duplicate fields
if ($params["field_name"][0] != "Formatting" && CRM_Core_BAO_UFField::duplicateField($params, $ids)) {
CRM_Core_Session::setStatus(ts('The selected field already exists in this profile.'), ts('Field Not Added'), 'error');
}
}
+ /**
+ * Validation rule to prevent multiple fields of primary location type within the same communication type.
+ *
+ * @param Array $fields Submitted fields
+ * @param String $profileFieldName Group Id.
+ * @param Array $groupFields List of fields already in the group
+ * @param Array $errors Collect errors
+ *
+ * @static
+ * @access public
+ */
+ static function formRulePrimaryCheck($fields, $profileFieldName, $groupFields, &$errors) {
+ //FIXME: This may need to also apply to website fields if they are refactored to allow more than one per profile
+ $checkPrimary = array('phone' => 'civicrm_phone.phone', 'phone_and_ext' => 'civicrm_phone.phone');
+ $whereCheck = NULL;
+ $primaryOfSameTypeFound = NULL;
+ $fieldID = empty($fields['field_id']) ? 0 : $fields['field_id'];
+ // Is this a primary location type field of interest
+ if (array_key_exists($profileFieldName, $checkPrimary)) {
+ $whereCheck = $checkPrimary[$profileFieldName];
+ }
+ $potentialLocationType = CRM_Utils_Array::value(2, $fields['field_name']);
+
+ if ($whereCheck && $potentialLocationType == 0) {
+ $primaryOfSameTypeFound = '';
+
+ foreach ($groupFields as $groupField) {
+ // if it is a phone
+ if ($groupField['where'] == $whereCheck && is_null($groupField['location_type_id']) && $groupField['field_id'] != $fieldID) {
+ $primaryOfSameTypeFound = $groupField['title'];
+ break;
+ }
+ }
+ if ($primaryOfSameTypeFound) {
+ $errors['field_name'] = ts('You have already added a primary location field of this type: %1', $primaryOfSameTypeFound);
+ }
+ }
+ }
+
/**
* global validation rules for the form
*
* @param array $fields posted values of the form
*
+ * @param $files
+ * @param $self
+ *
* @return array list of errors to be posted back to the form
* @static
* @access public
$errors['is_view'] = ts('A View Only field cannot be required');
}
- $fieldName = $fields['field_name'][0];
- if (!$fieldName) {
+ $entityName = $fields['field_name'][0];
+ if (!$entityName) {
$errors['field_name'] = ts('Please select a field name');
}
- if ($in_selector && in_array($fieldName, array(
+ if ($in_selector && in_array($entityName, array(
'Contribution', 'Participant', 'Membership', 'Activity'))) {
- $errors['in_selector'] = ts("'In Selector' cannot be checked for %1 fields.", array(1 => $fieldName));
+ $errors['in_selector'] = ts("'In Selector' cannot be checked for %1 fields.", array(1 => $entityName));
}
$isCustomField = FALSE;
}
}
+ // Get list of fields already in the group
+ $groupFields = CRM_Core_BAO_UFGroup::getFields($fields['group_id'], FALSE, NULL, NULL, NULL, TRUE, NULL, TRUE);
+ // Check if we already added a primary field of the same communication type
+ self::formRulePrimaryCheck($fields, $profileFieldName, $groupFields, $errors);
+
//check profile is configured for double option process
//adding group field, email field should be present in the group
//fixed for issue CRM-2861 & CRM-4153