'name'
);
$this->_gLabel = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gid, 'title');
- $this->_domainSpecific = in_array($this->_gName, CRM_Core_OptionGroup::$_domainIDGroups);
+ $this->_domainSpecific = CRM_Core_OptionGroup::isDomainOptionGroup($this->_gName);
$url = "civicrm/admin/options/{$this->_gName}";
$params = "reset=1";
$session->pushUserContext(CRM_Utils_System::url($url, $params));
$this->assign('id', $this->_id);
- if ($this->_id && in_array($this->_gName, CRM_Core_OptionGroup::$_domainIDGroups)) {
+ if ($this->_id && CRM_Core_OptionGroup::isDomainOptionGroup($this->_gName)) {
$domainID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'domain_id', 'id');
if (CRM_Core_Config::domainID() != $domainID) {
CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.'));
$url = CRM_Utils_System::url('civicrm/admin/campaign/surveyType', 'reset=1');
$session->pushUserContext($url);
- if ($this->_id && in_array($this->_gName, CRM_Core_OptionGroup::$_domainIDGroups)) {
+ if ($this->_id && CRM_Core_OptionGroup::isDomainOptionGroup($this->_gName)) {
$domainID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'domain_id', 'id');
if (CRM_Core_Config::domainID() != $domainID) {
CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.'));
$optionValue = new CRM_Core_DAO_OptionValue();
$optionValue->copyValues($params);
- $isDomainOptionGroup = in_array($groupName, CRM_Core_OptionGroup::$_domainIDGroups);
+ $isDomainOptionGroup = CRM_Core_OptionGroup::isDomainOptionGroup($groupName);
// 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();
// CRM-21737 languages option group does not use unique values but unique names.
$dao->name = $params['name'];
}
- if (in_array($groupName, CRM_Core_OptionGroup::$_domainIDGroups)) {
+ if (CRM_Core_OptionGroup::isDomainOptionGroup($groupName)) {
$dao->domain_id = $optionValue->domain_id;
}
$dao->option_group_id = $params['option_group_id'];
/**
* $_domainIDGroups array maintains the list of option groups for whom
* domainID is to be considered.
+ *
+ * FIXME: Hardcoded list = bad. It would be better to make this a column in the civicrm_option_group table
* @var array
*/
public static $_domainIDGroups = [
'grant_type',
];
+ /**
+ * @param $groupName
+ * @return bool
+ */
+ public static function isDomainOptionGroup($groupName) {
+ return in_array($groupName, self::$_domainIDGroups, TRUE);
+ }
+
/**
* @param CRM_Core_DAO $dao
* @param bool $flip
$orderBy = 'weight'
) {
$cache = CRM_Utils_Cache::singleton();
- if (in_array($name, self::$_domainIDGroups)) {
+ if (self::isDomainOptionGroup($name)) {
$cacheKey = self::createCacheKey($name, CRM_Core_I18n::getLocale(), $flip, $grouping, $localize, $condition, $labelColumnName, $onlyActive, $keyColumnName, $orderBy, CRM_Core_Config::domainID());
}
else {
}
$query .= " AND ($componentClause) ";
}
- if (in_array($name, self::$_domainIDGroups)) {
+ if (self::isDomainOptionGroup($name)) {
$query .= " AND v.domain_id = " . CRM_Core_Config::domainID();
}
AND g.is_active = 1
AND v.is_default = 1
";
- if (in_array($groupName, self::$_domainIDGroups)) {
+ if (self::isDomainOptionGroup($groupName)) {
$query .= " AND v.domain_id = " . CRM_Core_Config::domainID();
}
if ($optionGroupID) {
$dao->option_group_id = $optionGroupID;
- if (in_array($groupName, CRM_Core_OptionGroup::$_domainIDGroups)) {
+ if (CRM_Core_OptionGroup::isDomainOptionGroup($groupName)) {
$dao->domain_id = CRM_Core_Config::domainID();
}
$params[2] = [$groupName, 'String'];
}
- if (in_array($groupName, CRM_Core_OptionGroup::$_domainIDGroups)) {
+ if (CRM_Core_OptionGroup::isDomainOptionGroup($groupName)) {
$where .= " AND option_value.domain_id = " . CRM_Core_Config::domainID();
}
$record[$fieldName] = NULL;
}
}
- // Special handing of current_domain
+ // Should references be limited to the current domain?
+ $limitRefsByDomain = $entityType === 'OptionGroup' && \CRM_Core_OptionGroup::isDomainOptionGroup($record['name']) ? \CRM_Core_BAO_Domain::getDomain()->id : FALSE;
foreach ($allFields as $fieldName => $field) {
if (($field['fk_entity'] ?? NULL) === 'Domain') {
$alias = $fieldName . '.name';
- if (isset($record[$alias]) && $record[$alias] === \CRM_Core_BAO_Domain::getDomain()->name) {
- unset($record[$alias]);
- $record[$fieldName] = 'current_domain';
+ if (isset($record[$alias])) {
+ // If this entity is for a specific domain, limit references to that same domain
+ if ($fieldName === 'domain_id') {
+ $limitRefsByDomain = \CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Domain', $record[$alias], 'id', 'name');
+ }
+ // Swap current domain for special API keyword
+ if ($record[$alias] === \CRM_Core_BAO_Domain::getDomain()->name) {
+ unset($record[$alias]);
+ $record[$fieldName] = 'current_domain';
+ }
}
}
}
$references = [];
foreach ($dao->findReferences() as $reference) {
$refEntity = \CRM_Utils_Array::first($reference::fields())['entity'] ?? '';
+ // Limit references by domain
+ if (property_exists($reference, 'domain_id')) {
+ if (!isset($reference->domain_id)) {
+ $reference->find(TRUE);
+ }
+ if (isset($reference->domain_id) && $reference->domain_id != $limitRefsByDomain) {
+ continue;
+ }
+ }
$references[$refEntity][] = $reference;
}
foreach ($references as $refEntity => $records) {
->addChain('export', OptionGroup::export()->setId('$id'))
->execute()->first();
$this->assertEquals('from_email_address', $result['export'][1]['params']['values']['option_group_id.name']);
- $this->assertEquals('current_domain', $result['export'][1]['params']['values']['domain_id']);
$this->assertNull($result['export'][1]['params']['values']['visibility_id']);
$this->assertStringStartsWith('OptionGroup_from_email_address_OptionValue_', $result['export'][1]['name']);
+ // All references should be from the current domain
+ foreach (array_slice($result['export'], 1) as $reference) {
+ $this->assertEquals('current_domain', $reference['params']['values']['domain_id']);
+ }
}
public function testManagedNavigationWeights() {