X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FBAO%2FCustomField.php;h=5fac6b6f60ceb9ced2a228ee3033c6be9b40fdb8;hb=8783107356ceb57f51b6fab507861e8a22d34f20;hp=f2ad275a4b1e41152742ae58af3a0050e60c6bb3;hpb=27f0b7e5ba27f772fbb63cb34882c7c16c02f86e;p=civicrm-core.git diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index f2ad275a4b..5fac6b6f60 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -125,7 +125,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { * * @param array $params (reference) an assoc array of name/value pairs * - * @return object CRM_Core_DAO_CustomField object + * @return CRM_Core_DAO_CustomField object * @access public * @static */ @@ -151,7 +151,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { $indexExist = FALSE; //as during create if field is_searchable we had created index. - if (CRM_Utils_Array::value('id', $params)) { + if (!empty($params['id'])) { $indexExist = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $params['id'], 'is_searchable'); } @@ -180,8 +180,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { } } else { - if (CRM_Utils_Array::value('default_option', $params) - && isset($params['option_value'][$params['default_option']]) + if (!empty($params['default_option']) && isset($params['option_value'][$params['default_option']]) ) { $params['default_value'] = $params['option_value'][$params['default_option']]; } @@ -244,14 +243,14 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { } // check for orphan option groups - if (CRM_Utils_Array::value('option_group_id', $params)) { - if (CRM_Utils_Array::value('id', $params)) { + if (!empty($params['option_group_id'])) { + if (!empty($params['id'])) { self::fixOptionGroups($params['id'], $params['option_group_id']); } // if we dont have a default value // retrive it from one of the other custom fields which use this option group - if (!CRM_Utils_Array::value('default_value', $params)) { + if (empty($params['default_value'])) { //don't insert only value separator as default value, CRM-4579 $defaultValue = self::getOptionGroupDefault($params['option_group_id'], $params['html_type'] @@ -283,7 +282,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { $customField->find(TRUE); //create/drop the index when we toggle the is_searchable flag - if (CRM_Utils_Array::value('id', $params)) { + if (!empty($params['id'])) { self::createField($customField, 'modify', $indexExist); } else { @@ -619,7 +618,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { foreach ($fields as $id => $values) { // for now we should not allow multiple fields in profile / export etc, hence unsetting if (!$search && - (CRM_Utils_Array::value('is_multiple', $values) && !$withMultiple) + (!empty($values['is_multiple']) && !$withMultiple) ) { continue; } @@ -742,18 +741,37 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { } $field = self::getFieldObject($fieldId); - + // Custom field HTML should indicate group+field name $groupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $field->custom_group_id); $dataCrmCustomVal = $groupName.':'.$field->name; $dataCrmCustomAttr = 'data-crm-custom="'.$dataCrmCustomVal.'"'; $field->attributes .= $dataCrmCustomAttr; - + // Fixed for Issue CRM-2183 if ($field->html_type == 'TextArea' && $search) { $field->html_type = 'Text'; } + // FIXME: Why are select state/country separate widget types? + if (in_array($field->html_type, array('Select', 'Multi-Select', 'Select State/Province', 'Multi-Select State/Province', 'Select Country', 'Multi-Select Country'))) { + $selectAttributes = array( + 'data-crm-custom' => $dataCrmCustomVal, + 'class' => 'crm-select2', + ); + if (strpos($field->html_type, 'Multi') === 0) { + $selectAttributes['multiple'] = 'multiple'; + } + } + // Add data so popup link. Normally this is handled by CRM_Core_Form->addSelect + if (in_array($field->html_type, array('Select', 'Multi-Select')) && !$search && CRM_Core_Permission::check('administer CiviCRM')) { + $selectAttributes += array( + 'data-api-entity' => 'contact', // FIXME: This works because the getoptions api isn't picky about custom fields, but it's WRONG + 'data-api-field' => 'custom_' . $field->id, + 'data-option-edit-path' => 'civicrm/admin/options/' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $field->option_group_id), + ); + } + if (!isset($label)) { $label = $field->label; } @@ -831,7 +849,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { 'timeFormat' => $field->time_format, 'startOffset' => $field->start_date_years, 'endOffset' => $field->end_date_years, - 'data-crm-custom' => $dataCrmCustomVal, + 'data-crm-custom' => $dataCrmCustomVal, )); } break; @@ -845,16 +863,19 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { foreach ($customOption as $v => $l) { $choice[] = $qf->createElement('radio', NULL, '', $l, (string)$v, $field->attributes); } - $qf->addGroup($choice, $elementName, $label); + $group = $qf->addGroup($choice, $elementName, $label); } else { $choice[] = $qf->createElement('radio', NULL, '', ts('Yes'), '1', $field->attributes); $choice[] = $qf->createElement('radio', NULL, '', ts('No'), '0', $field->attributes); - $qf->addGroup($choice, $elementName, $label); + $group = $qf->addGroup($choice, $elementName, $label); } if ($useRequired && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } + else { + $group->setAttribute('unselectable', TRUE); + } break; case 'Select': @@ -865,7 +886,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { array( '' => ts('- select -')) + $selectOption, $useRequired && !$search, - $dataCrmCustomAttr + $selectAttributes ); break; @@ -889,7 +910,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { 'size' => 5, 'style' => '', 'class' => 'advmultiselect', - 'data-crm-custom' => $dataCrmCustomVal, + 'data-crm-custom' => $dataCrmCustomVal, ) ); @@ -910,7 +931,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { ) { $selectOption['CiviCRM_OP_OR'] = ts('Select to match ANY; unselect to match ALL'); } - $qf->addElement('select', $elementName, $label, $selectOption, array('size' => '5', 'multiple', 'data-crm-custom' => $dataCrmCustomVal)); + $qf->addElement('select', $elementName, $label, $selectOption, $selectAttributes); if ($useRequired && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); @@ -956,15 +977,16 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { $stateOption = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(); $qf->add('select', $elementName, $label, $stateOption, $useRequired && !$search, - $dataCrmCustomAttr + $selectAttributes ); + $qf->_stateCountryMap['state_province'][] = $elementName; break; case 'Multi-Select State/Province': //Add Multi-select State/Province $stateOption = CRM_Core_PseudoConstant::stateProvince(); - $qf->addElement('select', $elementName, $label, $stateOption, array('size' => '5', 'multiple', 'data-crm-custom' => $dataCrmCustomVal)); + $qf->addElement('select', $elementName, $label, $stateOption, $selectAttributes); if ($useRequired && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } @@ -975,14 +997,15 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { $countryOption = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(); $qf->add('select', $elementName, $label, $countryOption, $useRequired && !$search, - $dataCrmCustomAttr + $selectAttributes ); + $qf->_stateCountryMap['country'][] = $elementName; break; case 'Multi-Select Country': //Add Country $countryOption = CRM_Core_PseudoConstant::country(); - $qf->addElement('select', $elementName, $label, $countryOption, array('size' => '5', 'multiple', 'data-crm-custom' => $dataCrmCustomVal)); + $qf->addElement('select', $elementName, $label, $countryOption, $selectAttributes); if ($useRequired && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } @@ -1180,7 +1203,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { if ($value) { $display = ts('Yes'); } - elseif ($value === '0') { + elseif ((string)$value === '0') { $display = ts('No'); } } @@ -1345,7 +1368,6 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { $display = $value; } } - return $display ? $display : $value; } @@ -1558,7 +1580,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { if (is_array($customFieldExtend)) { $customFieldExtend = $customFieldExtend[0]; } - + if (in_array($customFieldExtend, CRM_Contact_BAO_ContactType::subTypes() )) { @@ -1583,7 +1605,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { } // return if field is a 'code' field - if (CRM_Utils_Array::value('is_view', $customFields[$customFieldId])) { + if (!empty($customFields[$customFieldId]['is_view'])) { return; } @@ -2055,7 +2077,7 @@ AND cf.id = %1"; $customOptionGroup[$cacheKey] = NULL; } - if (!CRM_Utils_Array::value($cacheKey, $customOptionGroup)) { + if (empty($customOptionGroup[$cacheKey])) { $whereClause = '( g.is_active = 1 AND f.is_active = 1 )'; //support for single as well as array format.