Skip to content

Commit

Permalink
Merge pull request #14670 from eileenmcnaughton/cust_field_2
Browse files Browse the repository at this point in the history
[REF] do not receive  by reference in CustomField::create
  • Loading branch information
seamuslee001 authored and eileenmcnaughton committed Jun 29, 2019
2 parents 886b8ee + f557467 commit 6d65817
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions CRM/Core/BAO/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,15 @@ public static function dataToHtml() {
*
* @return CRM_Core_DAO_CustomField
*/
public static function create(&$params) {
$origParams = array_merge(array(), $params);
public static function create($params) {
$transaction = new CRM_Core_Transaction();
$origParams = array_merge([], $params);

$op = empty($params['id']) ? 'create' : 'edit';

CRM_Utils_Hook::pre($op, 'CustomField', CRM_Utils_Array::value('id', $params), $params);

if ($op == 'create') {
if ($op === 'create') {
CRM_Core_DAO::setCreateDefaults($params, self::getDefaults());
if (!isset($params['column_name'])) {
// if add mode & column_name not present, calculate it.
$params['column_name'] = strtolower(CRM_Utils_String::munge($params['label'], '_', 32));
Expand Down Expand Up @@ -207,8 +208,6 @@ public static function create(&$params) {
break;
}

$transaction = new CRM_Core_Transaction();

$htmlType = CRM_Utils_Array::value('html_type', $params);
$dataType = CRM_Utils_Array::value('data_type', $params);
$allowedOptionTypes = array('String', 'Int', 'Float', 'Money');
Expand Down Expand Up @@ -266,15 +265,6 @@ public static function create(&$params) {

$customField = new CRM_Core_DAO_CustomField();
$customField->copyValues($params);
if ($op == 'create') {
$customField->is_required = CRM_Utils_Array::value('is_required', $params, FALSE);
$customField->is_searchable = CRM_Utils_Array::value('is_searchable', $params, FALSE);
$customField->in_selector = CRM_Utils_Array::value('in_selector', $params, FALSE);
$customField->is_search_range = CRM_Utils_Array::value('is_search_range', $params, FALSE);
//CRM-15792 - Custom field gets disabled if is_active not set
$customField->is_active = CRM_Utils_Array::value('is_active', $params, TRUE);
$customField->is_view = CRM_Utils_Array::value('is_view', $params, FALSE);
}
$customField->save();

// make sure all values are present in the object for further processing
Expand Down Expand Up @@ -2167,6 +2157,24 @@ public static function customOptionGroup($includeFieldIds = NULL) {
return $customOptionGroup[$cacheKey];
}

/**
* Get defaults for new entity.
*
* @return array
*/
public static function getDefaults() {
return [
'is_required' => FALSE,
'is_searchable' => FALSE,
'in_selector' => FALSE,
'is_search_range' => FALSE,
//CRM-15792 - Custom field gets disabled if is_active not set
// this would ideally be a mysql default.
'is_active' => TRUE,
'is_view' => FALSE,
];
}

/**
* Fix orphan groups.
*
Expand Down

0 comments on commit 6d65817

Please sign in to comment.