* @throws \CiviCRM_API3_Exception
*/
public static function bulkSave($bulkParams, $defaults = []) {
- $addedColumns = $sql = $tables = $customFields = [];
+ $addedColumns = $sql = $customFields = [];
foreach ($bulkParams as $index => $fieldParams) {
$params = array_merge($defaults, $fieldParams);
$customField = self::createCustomFieldRecord($params);
if (!isset($params['custom_group_id'])) {
$params['custom_group_id'] = civicrm_api3('CustomField', 'getvalue', ['id' => $customField->id, 'return' => 'custom_group_id']);
}
- if (!isset($params['table_name'])) {
- if (!isset($tables[$params['custom_group_id']])) {
- $tables[$params['custom_group_id']] = civicrm_api3('CustomGroup', 'getvalue', [
- 'id' => $params['custom_group_id'],
- 'return' => 'table_name',
- ]);
- }
- $params['table_name'] = $tables[$params['custom_group_id']];
- }
- $sql[$params['table_name']][] = $fieldSQL;
- $addedColumns[$params['table_name']][] = $customField->name;
+ $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customField->custom_group_id, 'table_name');
+ $sql[$tableName][] = $fieldSQL;
+ $addedColumns[$tableName][] = $customField->name;
$customFields[$index] = $customField;
}
$logging->fixSchemaDifferencesFor($tableName, ['ADD' => $addedColumns[$tableName]]);
}
- Civi::service('sql_triggers')->rebuild($params['table_name'], TRUE);
+ Civi::service('sql_triggers')->rebuild($tableName, TRUE);
}
CRM_Utils_System::flushCache();
foreach ($customFields as $index => $customField) {
$cacheKey .= $inline ? '_1_' : '_0_';
$cacheKey .= $onlyParent ? '_1_' : '_0_';
$cacheKey .= $onlySubType ? '_1_' : '_0_';
- $cacheKey .= $checkPermission ? '_1_' : '_0_';
+ $cacheKey .= $checkPermission ? '_1_' . CRM_Core_Session::getLoggedInContactID() . '_' : '_0_0_';
$cacheKey .= '_' . CRM_Core_Config::domainID() . '_';
$cgTable = CRM_Core_DAO_CustomGroup::getTableName();
$fields = Civi::Cache('fields')->get("custom importableFields $cacheKey");
if ($fields === NULL) {
- $cfTable = self::getTableName();
$extends = '';
if (is_array($customDataType)) {
// Temporary hack - in 5.27 a new field is added to civicrm_custom_field. There is a high
// risk this function is called before the upgrade page can be reached and if
// so it will potentially result in fatal error.
- $serializeField = CRM_Core_BAO_Domain::isDBVersionAtLeast('5.27.alpha1') ? "$cfTable.serialize," : '';
+ $serializeField = CRM_Core_BAO_Domain::isDBVersionAtLeast('5.27.alpha1') ? "custom_field.serialize," : '';
- $query = "SELECT $cfTable.id, $cfTable.label,
+ $query = "SELECT custom_field.id, custom_field.label,
$cgTable.title,
- $cfTable.data_type,
- $cfTable.html_type,
- $cfTable.default_value,
- $cfTable.options_per_line, $cfTable.text_length,
- $cfTable.custom_group_id,
- $cfTable.is_required,
- $cfTable.column_name,
- $cgTable.extends, $cfTable.is_search_range,
+ custom_field.data_type,
+ custom_field.html_type,
+ custom_field.default_value,
+ custom_field.options_per_line, custom_field.text_length,
+ custom_field.custom_group_id,
+ custom_field.is_required,
+ custom_field.column_name,
+ $cgTable.extends, custom_field.is_search_range,
$cgTable.extends_entity_column_value,
$cgTable.extends_entity_column_id,
- $cfTable.is_view,
- $cfTable.option_group_id,
- $cfTable.date_format,
- $cfTable.time_format,
+ custom_field.is_view,
+ custom_field.option_group_id,
+ custom_field.date_format,
+ custom_field.time_format,
$cgTable.is_multiple,
$serializeField
$cgTable.table_name,
og.name as option_group_name
- FROM $cfTable
+ FROM civicrm_custom_field custom_field
INNER JOIN $cgTable
- ON $cfTable.custom_group_id = $cgTable.id
+ ON custom_field.custom_group_id = $cgTable.id
LEFT JOIN civicrm_option_group og
- ON $cfTable.option_group_id = og.id
+ ON custom_field.option_group_id = og.id
WHERE ( 1 ) ";
if (!$showAll) {
- $query .= " AND $cfTable.is_active = 1 AND $cgTable.is_active = 1 ";
+ $query .= " AND custom_field.is_active = 1 AND $cgTable.is_active = 1 ";
}
if ($inline) {
$query .= " $extends AND $permissionClause
ORDER BY $cgTable.weight, $cgTable.title,
- $cfTable.weight, $cfTable.label";
+ custom_field.weight, custom_field.label";
$dao = CRM_Core_DAO::executeQuery($query);
// Search field is always multi-select
if ($search || (self::isSerialized($field) && $widget === 'Select')) {
- $fieldAttributes['class'] .= ltrim($fieldAttributes['class'] ?? '' . ' huge');
+ $fieldAttributes['class'] = ltrim(($fieldAttributes['class'] ?? '') . ' huge');
$fieldAttributes['multiple'] = 'multiple';
$fieldAttributes['placeholder'] = $placeholder;
}
// For all select elements
case 'Select':
- $fieldAttributes['class'] .= ltrim($fieldAttributes['class'] ?? '' . ' crm-select2');
+ $fieldAttributes['class'] = ltrim(($fieldAttributes['class'] ?? '') . ' crm-select2');
if ($field->is_search_range && $search && in_array($field->data_type, $rangeDataTypes)) {
$qf->add('text', $elementName . '_from', $label . ' ' . ts('From'), $fieldAttributes);
$qf->add('text', $elementName . '_to', ts('To'), $fieldAttributes);
if (!CRM_Core_Permission::check('access contact reference fields')) {
break;
}
- $fieldAttributes['class'] = ltrim($fieldAttributes['class'] ?? '' . ' crm-form-contact-reference huge');
+ $fieldAttributes['class'] = ltrim(($fieldAttributes['class'] ?? '') . ' crm-form-contact-reference huge');
$fieldAttributes['data-api-entity'] = 'Contact';
$element = $qf->add('text', $elementName, $label, $fieldAttributes, $useRequired && !$search);
$fieldAttributes += [
'entity' => 'OptionValue',
'placeholder' => $placeholder,
- 'multiple' => $search,
+ 'multiple' => $search ? TRUE : !empty($field->serialize),
'api' => [
'params' => ['option_group_id' => $field->option_group_id, 'is_active' => 1],
],
}
}
elseif (self::isSerialized($customFields[$customFieldId])) {
+ // Select2 v3 returns a comma-separated string.
+ if ($customFields[$customFieldId]['html_type'] == 'Autocomplete-Select' && is_string($value)) {
+ $value = explode(',', $value);
+ }
+
$value = $value ? CRM_Utils_Array::implodePadded($value) : '';
}