From ff62528042292809a54ca46d1efe4b6cb3195a6d Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 4 Jul 2018 20:09:03 +1200 Subject: [PATCH] Simplify input params on OptionValue::addOptionValue The addOptionValue function is one we should probably deprecate/ remove but towards that we should start to remove it. This commit removes some complexity by passing option_group_name rather than groupParams - which is a more accurate reflection of usage and removes ambiguity around the passing by reference --- CRM/Admin/Form/Options.php | 3 +-- CRM/Campaign/Form/SurveyType.php | 3 +-- CRM/Core/OptionValue.php | 21 ++++++++------------- CRM/Report/Form/Register.php | 3 +-- api/v3/ActivityType.php | 3 +-- 5 files changed, 12 insertions(+), 21 deletions(-) diff --git a/CRM/Admin/Form/Options.php b/CRM/Admin/Form/Options.php index f68718d881..7083e80426 100644 --- a/CRM/Admin/Form/Options.php +++ b/CRM/Admin/Form/Options.php @@ -484,8 +484,7 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form { $params['color'] = 'null'; } - $groupParams = array('name' => ($this->_gName)); - $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id); + $optionValue = CRM_Core_OptionValue::addOptionValue($params, $this->_gName, $this->_action, $this->_id); // CRM-11516 if (!empty($params['financial_account_id'])) { diff --git a/CRM/Campaign/Form/SurveyType.php b/CRM/Campaign/Form/SurveyType.php index cad02eabe6..0cce9e4b35 100644 --- a/CRM/Campaign/Form/SurveyType.php +++ b/CRM/Campaign/Form/SurveyType.php @@ -156,9 +156,8 @@ class CRM_Campaign_Form_SurveyType extends CRM_Admin_Form { $params['filter'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'filter', 'id'); } - $groupParams = array('name' => ($this->_gName)); $params['component_id'] = CRM_Core_Component::getComponentID('CiviCampaign'); - $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id); + $optionValue = CRM_Core_OptionValue::addOptionValue($params, $this->_gName, $this->_action, $this->_id); CRM_Core_Session::setStatus(ts('The Survey type \'%1\' has been saved.', array(1 => $optionValue->label)), ts('Saved'), 'success'); } diff --git a/CRM/Core/OptionValue.php b/CRM/Core/OptionValue.php index 27a1a756f0..4b1e5105ba 100644 --- a/CRM/Core/OptionValue.php +++ b/CRM/Core/OptionValue.php @@ -187,7 +187,7 @@ class CRM_Core_OptionValue { * * @param array $params * Array containing exported values from the invoking form. - * @param array $groupParams + * @param string $optionGroupName * Array containing group fields whose option-values is to retrieved/saved. * @param $action * @param int $optionValueID Has the id of the optionValue being edited, disabled ..etc. @@ -196,22 +196,17 @@ class CRM_Core_OptionValue { * @return CRM_Core_DAO_OptionValue * */ - public static function addOptionValue(&$params, &$groupParams, $action, $optionValueID) { + public static function addOptionValue(&$params, $optionGroupName, $action, $optionValueID) { $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); // checking if the group name with the given id or name (in $groupParams) exists - if (!empty($groupParams)) { - $config = CRM_Core_Config::singleton(); - $groupParams['is_active'] = 1; - $optionGroup = CRM_Core_BAO_OptionGroup::retrieve($groupParams, $defaults); - } + $groupParams = ['name' => $optionGroupName, 'is_active' => 1]; + $optionGroup = CRM_Core_BAO_OptionGroup::retrieve($groupParams, $defaults); - // if the corresponding group doesn't exist, create one, provided $groupParams has 'name' in it. + // if the corresponding group doesn't exist, create one. if (!$optionGroup->id) { - if ($groupParams['name']) { - $newOptionGroup = CRM_Core_BAO_OptionGroup::add($groupParams, $defaults); - $params['weight'] = 1; - $optionGroupID = $newOptionGroup->id; - } + $newOptionGroup = CRM_Core_BAO_OptionGroup::add($groupParams); + $params['weight'] = 1; + $optionGroupID = $newOptionGroup->id; } else { $optionGroupID = $optionGroup->id; diff --git a/CRM/Report/Form/Register.php b/CRM/Report/Form/Register.php index 094520df38..4f7bd46028 100644 --- a/CRM/Report/Form/Register.php +++ b/CRM/Report/Form/Register.php @@ -191,8 +191,7 @@ class CRM_Report_Form_Register extends CRM_Core_Form { // get the submitted form values. $params = $this->controller->exportValues($this->_name); - $groupParams = array('name' => ('report_template')); - $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id); + $optionValue = CRM_Core_OptionValue::addOptionValue($params, 'report_template', $this->_action, $this->_id); CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array( 1 => 'Report Template', 2 => $optionValue->label, diff --git a/api/v3/ActivityType.php b/api/v3/ActivityType.php index 3f6d121f1a..db7bd23d73 100644 --- a/api/v3/ActivityType.php +++ b/api/v3/ActivityType.php @@ -72,13 +72,12 @@ function civicrm_api3_activity_type_get($params) { function civicrm_api3_activity_type_create($params) { $action = 1; - $groupParams = array('name' => 'activity_type'); if ($optionValueID = CRM_Utils_Array::value('option_value_id', $params)) { $action = 2; } - $activityObject = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $action, $optionValueID); + $activityObject = CRM_Core_OptionValue::addOptionValue($params, 'activity_type', $action, $optionValueID); $activityType = array(); _civicrm_api3_object_to_array($activityObject, $activityType[$activityObject->id]); return civicrm_api3_create_success($activityType, $params, 'activity_type', 'create'); -- 2.25.1