This fixes some issues in tests involving enableComponents.
Upshot: The UI for setting URLs/directories now displays the default values properly.
'templateCompileDir' => array('runtime'),
'templateDir' => array('runtime'),
- 'customFileUploadDir' => array('setting-path', NULL, '[civicrm.files]/custom/', array('mkdir', 'restrict')),
+ 'customFileUploadDir' => array('setting-path', NULL, array('mkdir', 'restrict')),
'customPHPPathDir' => array('setting-path'),
'customTemplateDir' => array('setting-path'),
'extensionsDir' => array('setting-path'),
- 'imageUploadDir' => array('setting-path', NULL, '[civicrm.files]/persist/contribute/', array('mkdir')),
- 'uploadDir' => array('setting-path', NULL, '[civicrm.files]/upload/', array('mkdir', 'restrict')),
+ 'imageUploadDir' => array('setting-path', NULL, array('mkdir')),
+ 'uploadDir' => array('setting-path', NULL, array('mkdir', 'restrict')),
'customCSSURL' => array('setting-url-abs'),
'extensionsURL' => array('setting-url-abs'),
- 'imageUploadURL' => array('setting-url-abs', NULL, '[civicrm.files]/persist/contribute/'),
- 'resourceBase' => array('setting-url-rel', 'userFrameworkResourceURL', '[civicrm]/.'),
- 'userFrameworkResourceURL' => array('setting-url-abs', NULL, '[civicrm]/.'),
+ 'imageUploadURL' => array('setting-url-abs'),
+ 'resourceBase' => array('setting-url-rel', 'userFrameworkResourceURL'),
+ 'userFrameworkResourceURL' => array('setting-url-abs'),
'geocodeMethod' => array('callback', 'CRM_Utils_Geocode', 'getProviderClass'),
'defaultCurrencySymbol' => array('callback', 'CRM_Core_BAO_Country', 'getDefaultCurrencySymbol'),
return $this->getSettings()->get($name);
case 'setting-path':
- // Array(0 => $type, 1 => $setting, 2 => $default, 3 => $actions).
+ // Array(0 => $type, 1 => $setting, 2 => $actions).
$value = $this->getSettings()->get($name);
- if (empty($value) && isset($this->map[$k][2])) {
- $value = $this->map[$k][2];
- }
$value = Civi::paths()->getPath($value);
if ($value) {
$value = CRM_Utils_File::addTrailingSlash($value);
- if (isset($this->map[$k][3]) && in_array('mkdir', $this->map[$k][3])) {
+ if (isset($this->map[$k][2]) && in_array('mkdir', $this->map[$k][2])) {
CRM_Utils_File::createDir($value);
}
- if (isset($this->map[$k][3]) && in_array('restrict', $this->map[$k][3])) {
+ if (isset($this->map[$k][2]) && in_array('restrict', $this->map[$k][2])) {
CRM_Utils_File::restrictAccess($value);
}
}
return $value;
case 'setting-url-abs':
- // Array(0 => $type, 1 => $setting, 2 => $default).
$value = $this->getSettings()->get($name);
- if (empty($value) && isset($this->map[$k][2])) {
- $value = $this->map[$k][2];
- }
$this->cache[$k] = Civi::paths()->getUrl($value, 'absolute');
return $this->cache[$k];
case 'setting-url-rel':
- // Array(0 => $type, 1 => $setting, 2 => $default).
$value = $this->getSettings()->get($name);
- if (empty($value) && isset($this->map[$k][2])) {
- $value = $this->map[$k][2];
- }
$this->cache[$k] = Civi::paths()->getUrl($value, 'relative');
return $this->cache[$k];
public function __construct() {
$this
- ->register('civicrm', function () {
- return \CRM_Core_Config::singleton()->userSystem->getCiviSourceStorage();
- })
+ //->register('civicrm', function () {
+ // return \CRM_Core_Config::singleton()->userSystem->getCiviSourceStorage();
+ //})
->register('civicrm.root', function () {
return \CRM_Core_Config::singleton()->userSystem->getCiviSourceStorage();
})
*/
public function getUrl($value, $preferFormat = 'relative', $ssl = NULL) {
$defaultContainer = self::DEFAULT_URL;
- if ($value && $value{0} == '[' && preg_match(';^\[([a-zA-Z0-9\._]+)\]/(.*);', $value, $matches)) {
+ if ($value && $value{0} == '[' && preg_match(';^\[([a-zA-Z0-9\._]+)\](/(.*))$;', $value, $matches)) {
$defaultContainer = $matches[1];
- $value = $matches[2];
+ $value = empty($matches[3]) ? '.' : $matches[3];
}
if (empty($value)) {
*/
protected $values;
- protected $filteredValues;
-
/**
* @param int $domainId
* The domain for which we want settings.
$this->domainId = $domainId;
$this->contactId = $contactId;
$this->values = array();
- $this->filteredValues = array();
$this->combined = NULL;
}
*/
public function loadDefaults($defaults) {
$this->defaults = $defaults;
- $this->filteredValues = array();
$this->combined = NULL;
return $this;
}
*/
public function loadMandatory($mandatory) {
$this->mandatory = $mandatory;
- $this->filteredValues = array();
$this->combined = NULL;
return $this;
}
public function set($key, $value) {
$this->setDb($key, $value);
$this->values[$key] = $value;
- unset($this->filteredValues[$key]);
$this->combined = NULL;
return $this;
}
*/
protected function getDefaults($entity) {
if (!$this->useDefaults) {
- return array();
+ return self::getSystemDefaults($entity);
}
$cacheKey = 'defaults:' . $entity;
foreach ($specs as $key => $spec) {
$defaults[$key] = \CRM_Utils_Array::value('default', $spec);
}
+ \CRM_Utils_Array::extend($defaults, self::getSystemDefaults($entity));
$this->cache->set($cacheKey, $defaults);
}
return $defaults;
$bag->loadMandatory($this->getMandatory('domain'));
}
- foreach ($this->bagsByDomain as $bag) {
+ foreach ($this->bagsByContact as $bag) {
/** @var SettingsBag $bag */
$bag->loadValues();
$bag->loadDefaults($this->getDefaults('contact'));
return $this;
}
+ /**
+ * Get a list of critical system defaults.
+ *
+ * The setting system can be modified by extensions, which means that it's not fully available
+ * during bootstrap -- in particular, defaults cannot be loaded. For a very small number of settings,
+ * we must define defaults before the system bootstraps.
+ *
+ * @return array
+ */
+ private static function getSystemDefaults($entity) {
+ $defaults = array();
+ switch ($entity) {
+ case 'domain':
+ $defaults = array(
+ 'enable_components' => array('CiviEvent', 'CiviContribute', 'CiviMember', 'CiviMail', 'CiviReport', 'CiviPledge'),
+ 'customFileUploadDir' => '[civicrm.files]/custom/',
+ 'imageUploadDir' => '[civicrm.files]/persist/contribute/',
+ 'uploadDir' => '[civicrm.files]/upload/',
+ 'imageUploadURL' => '[civicrm.files]/persist/contribute/',
+ 'resourceBase' => '[civicrm.root]/',
+ 'userFrameworkResourceURL' => '[civicrm.root]/',
+ );
+ break;
+
+ }
+ return $defaults;
+ }
+
}
'help_text' => NULL,
),
'enable_components' => array(
+ 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults are loaded via SettingsBag::getSystemDefaults().',
'group_name' => 'CiviCRM Preferences',
'group' => 'core',
'name' => 'enable_components',
'style' => 'width:150px',
'class' => 'advmultiselect',
),
- 'default' => array('CiviEvent', 'CiviContribute', 'CiviMember', 'CiviMail', 'CiviReport', 'CiviPledge'),
+ 'default' => NULL,
'add' => '4.4',
'title' => 'Enable Components',
'is_domain' => '1',
return array(
'uploadDir' => array(
- 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults and other metadata may not be available during bootstrap.',
+ 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults are loaded via SettingsBag::getSystemDefaults().',
'group_name' => 'Directory Preferences',
'group' => 'directory',
'name' => 'uploadDir',
'help_text' => 'File system path where temporary CiviCRM files - such as import data files - are uploaded.',
),
'imageUploadDir' => array(
- 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults and other metadata may not be available during bootstrap.',
+ 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults are loaded via SettingsBag::getSystemDefaults().',
'group_name' => 'Directory Preferences',
'group' => 'directory',
'name' => 'imageUploadDir',
'help_text' => NULL,
),
'customFileUploadDir' => array(
- 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults and other metadata may not be available during bootstrap.',
+ 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults are loaded via SettingsBag::getSystemDefaults().',
'group_name' => 'Directory Preferences',
'group' => 'directory',
'name' => 'customFileUploadDir',
'help_text' => NULL,
),
'customTemplateDir' => array(
- 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults and other metadata may not be available during bootstrap.',
+ 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults are loaded via SettingsBag::getSystemDefaults().',
'group_name' => 'Directory Preferences',
'group' => 'directory',
'name' => 'customTemplateDir',
'help_text' => NULL,
),
'customPHPPathDir' => array(
- 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults and other metadata may not be available during bootstrap.',
+ 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults are loaded via SettingsBag::getSystemDefaults().',
'group_name' => 'Directory Preferences',
'group' => 'directory',
'name' => 'customPHPPathDir',
'help_text' => NULL,
),
'extensionsDir' => array(
- 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults and other metadata may not be available during bootstrap.',
+ 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults are loaded via SettingsBag::getSystemDefaults().',
'group_name' => 'Directory Preferences',
'group' => 'directory',
'name' => 'extensionsDir',
*/
return array(
'userFrameworkResourceURL' => array(
- 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults and other metadata may not be available during bootstrap.',
+ 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults are loaded via SettingsBag::getSystemDefaults().',
'group' => 'url',
'group_name' => 'URL Preferences',
'name' => 'userFrameworkResourceURL',
'validate_callback' => 'CRM_Utils_Rule::urlish',
),
'imageUploadURL' => array(
- 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults and other metadata may not be available during bootstrap.',
+ 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults are loaded via SettingsBag::getSystemDefaults().',
'group' => 'url',
'group_name' => 'URL Preferences',
'title' => 'Image Upload URL',
'validate_callback' => 'CRM_Utils_Rule::urlish',
),
'customCSSURL' => array(
- 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults and other metadata may not be available during bootstrap.',
+ 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults are loaded via SettingsBag::getSystemDefaults().',
'group' => 'url',
'group_name' => 'URL Preferences',
'name' => 'customCSSURL',
'validate_callback' => 'CRM_Utils_Rule::urlish',
),
'extensionsURL' => array(
- 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults and other metadata may not be available during bootstrap.',
+ 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults are loaded via SettingsBag::getSystemDefaults().',
'group' => 'url',
'group_name' => 'URL Preferences',
'title' => 'Extension Resource URL',