From 6651b27d75ab5ea0fdd9e9104bf0e74091bd8eb6 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 17 Nov 2021 21:56:24 -0500 Subject: [PATCH] OptionValue - Fix checking if domain is set Fixes a bug introduced in #19970 --- CRM/Core/BAO/OptionValue.php | 5 +++-- tests/phpunit/api/v4/Entity/ManagedEntityTest.php | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CRM/Core/BAO/OptionValue.php b/CRM/Core/BAO/OptionValue.php index cc40fb0e0ddd..6c1901caf9ce 100644 --- a/CRM/Core/BAO/OptionValue.php +++ b/CRM/Core/BAO/OptionValue.php @@ -170,7 +170,8 @@ public static function add(&$params, $ids = []) { $optionValue->copyValues($params); $isDomainOptionGroup = in_array($groupName, CRM_Core_OptionGroup::$_domainIDGroups); - if (empty($params['domain_id']) && $isDomainOptionGroup) { + // When creating a new option for a group that requires a domain, set default domain + if ($isDomainOptionGroup && empty($params['id']) && (empty($params['domain_id']) || CRM_Utils_System::isNull($params['domain_id']))) { $optionValue->domain_id = CRM_Core_Config::domainID(); } @@ -192,7 +193,7 @@ public static function add(&$params, $ids = []) { $p = [1 => [$params['option_group_id'], 'Integer']]; // Limit update by domain of option - $domain = $optionValue->domain_id ?? NULL; + $domain = CRM_Utils_System::isNull($optionValue->domain_id) ? NULL : $optionValue->domain_id; if (!$domain && $id && $isDomainOptionGroup) { $domain = CRM_Core_DAO::getFieldValue(__CLASS__, $id, 'domain_id'); } diff --git a/tests/phpunit/api/v4/Entity/ManagedEntityTest.php b/tests/phpunit/api/v4/Entity/ManagedEntityTest.php index 5cdd5e12d431..70403a1accb9 100644 --- a/tests/phpunit/api/v4/Entity/ManagedEntityTest.php +++ b/tests/phpunit/api/v4/Entity/ManagedEntityTest.php @@ -293,6 +293,8 @@ public function testOptionGroupAndValues() { 'is_active' => TRUE, 'is_reserved' => FALSE, 'weight' => 1, + 'is_default' => 1, + 'domain_id' => NULL, 'icon' => 'fa-test', ], ],