<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.7 |
+ | CiviCRM version 5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2018 |
+--------------------------------------------------------------------+
/**
* @param int|NULL $domainId
+ * For the default domain, leave $domainID as NULL.
* @param int|NULL $contactId
+ * For the default/active user's contact, leave $domainID as NULL.
* @return SettingsBag
+ * @throws \CRM_Core_Exception
+ * If there is no contact, then there's no SettingsBag, and we'll throw
+ * an exception.
*/
public function getBagByContact($domainId, $contactId) {
if ($domainId === NULL) {
$domainId = \CRM_Core_Config::domainID();
}
+ if ($contactId === NULL) {
+ $contactId = \CRM_Core_Session::getLoggedInContactID();
+ if (!$contactId) {
+ throw new \CRM_Core_Exception("Cannot access settings subsystem - user or domain is unavailable");
+ }
+ }
$key = "$domainId:$contactId";
if (!isset($this->bagsByContact[$key])) {
return self::getSystemDefaults($entity);
}
- $cacheKey = 'defaults:' . $entity;
+ $cacheKey = 'defaults_' . $entity;
$defaults = $this->cache->get($cacheKey);
if (!is_array($defaults)) {
$specs = SettingsMetadata::getMetadata(array(