OptionValue - Fix checking if domain is set
authorColeman Watts <coleman@civicrm.org>
Thu, 18 Nov 2021 02:56:24 +0000 (21:56 -0500)
committerColeman Watts <coleman@civicrm.org>
Thu, 18 Nov 2021 03:32:43 +0000 (22:32 -0500)
Fixes a bug introduced in #19970

CRM/Core/BAO/OptionValue.php
tests/phpunit/api/v4/Entity/ManagedEntityTest.php

index cc40fb0e0ddd6c3cba1f85d9cca870615e34943d..6c1901caf9ce20e74c98befad3c4ee6727037213 100644 (file)
@@ -170,7 +170,8 @@ class CRM_Core_BAO_OptionValue extends CRM_Core_DAO_OptionValue {
     $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 @@ class CRM_Core_BAO_OptionValue extends CRM_Core_DAO_OptionValue {
       $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');
       }
index 5cdd5e12d4317a235cb5b20f94f0c331b235afb9..70403a1accb905b1ab5277e6c365647e40e86a66 100644 (file)
@@ -293,6 +293,8 @@ class ManagedEntityTest extends UnitTestCase implements TransactionalInterface,
           'is_active' => TRUE,
           'is_reserved' => FALSE,
           'weight' => 1,
+          'is_default' => 1,
+          'domain_id' => NULL,
           'icon' => 'fa-test',
         ],
       ],