Skip to content

Commit

Permalink
OptionValue - Fix checking if domain is set
Browse files Browse the repository at this point in the history
Fixes a bug introduced in civicrm#19970
  • Loading branch information
colemanw committed Nov 18, 2021
1 parent 6272f9f commit 6651b27
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions CRM/Core/BAO/OptionValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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');
}
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/api/v4/Entity/ManagedEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ public function testOptionGroupAndValues() {
'is_active' => TRUE,
'is_reserved' => FALSE,
'weight' => 1,
'is_default' => 1,
'domain_id' => NULL,
'icon' => 'fa-test',
],
],
Expand Down

0 comments on commit 6651b27

Please sign in to comment.