diff --git a/code/model/SiteConfig.php b/code/model/SiteConfig.php index 89ea9a85..b7573d88 100644 --- a/code/model/SiteConfig.php +++ b/code/model/SiteConfig.php @@ -1,15 +1,8 @@ Title = _t('SiteConfig.SITENAMEDEFAULT', "Your Site Name"); + $this->Tagline = _t('SiteConfig.TAGLINEDEFAULT', "your tagline here"); + + // Allow these defaults to be overridden + parent::populateDefaults(); + } + /** * Get the fields that are sent to the CMS. In * your extensions: updateCMSFields($fields) @@ -84,13 +86,6 @@ class SiteConfig extends DataObject implements PermissionProvider { $topLevelCreatorsOptionsField->setSource($editorsOptionsSource); - // Translatable doesn't handle updateCMSFields on DataObjects, - // so add it here to save the current Locale, - // because onBeforeWrite does not work. - if(class_exists('Translatable') && Object::has_extension('SiteConfig',"Translatable")){ - $fields->push(new HiddenField("Locale")); - } - if (!Permission::check('EDIT_SITECONFIG')) { $fields->makeFieldReadonly($viewersOptionsField); $fields->makeFieldReadonly($viewerGroupsField); @@ -161,22 +156,14 @@ class SiteConfig extends DataObject implements PermissionProvider { * Get the current sites SiteConfig, and creates a new one * through {@link make_site_config()} if none is found. * - * @param string $locale * @return SiteConfig */ - static function current_site_config($locale = null) { - if(class_exists('Translatable') && Object::has_extension('SiteConfig',"Translatable")){ - $locale = isset($locale) ? $locale : Translatable::get_current_locale(); - $siteConfig = Translatable::get_one_by_locale('SiteConfig', $locale); - } else { - $siteConfig = DataObject::get_one('SiteConfig'); - } + static function current_site_config() { + if ($siteConfig = DataObject::get_one('SiteConfig')) return $siteConfig; - if (!$siteConfig) $siteConfig = self::make_site_config($locale); - - return $siteConfig; + return self::make_site_config(); } - + /** * Setup a default SiteConfig record if none exists */ @@ -191,39 +178,16 @@ class SiteConfig extends DataObject implements PermissionProvider { /** * Create SiteConfig with defaults from language file. - * if Translatable is enabled on SiteConfig, see if one already exist - * and use those values for the translated defaults. * * @param string $locale * @return SiteConfig */ - static function make_site_config($locale = null) { - if(class_exists('Translatable') && !$locale) $locale = Translatable::get_current_locale(); - - $siteConfig = new SiteConfig(); - $siteConfig->Title = _t('SiteConfig.SITENAMEDEFAULT',"Your Site Name"); - $siteConfig->Tagline = _t('SiteConfig.TAGLINEDEFAULT',"your tagline here"); + static function make_site_config() { + $config = SiteConfig::create(); + $config->write(); + return $config; + } - if(class_exists('Translatable') && $siteConfig->hasExtension('Translatable')){ - Translatable::disable_locale_filter(); - $defaultConfig = SiteConfig::get()->first(); - Translatable::enable_locale_filter(); - - if($defaultConfig){ - return $defaultConfig->createTranslation($locale); - } - - // TODO Copy view/edit group settings - - // set the correct Locale - $siteConfig->Locale = $locale; - } - - $siteConfig->write(); - - return $siteConfig; - } - /** * Can a user view pages on this site? This method is only * called if a page is set to Inherit, but there is nothing diff --git a/code/model/SiteTree.php b/code/model/SiteTree.php index 06f7c961..16d510a2 100644 --- a/code/model/SiteTree.php +++ b/code/model/SiteTree.php @@ -991,17 +991,13 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid * Stub method to get the site config, provided so it's easy to override */ function getSiteConfig() { - $altConfig = false; + if($this->hasMethod('alternateSiteConfig')) { $altConfig = $this->alternateSiteConfig(); + if($altConfig) return $altConfig; } - if($altConfig) { - return $altConfig; - } elseif(class_exists('Translatable') && $this->hasExtension('Translatable')) { - return SiteConfig::current_site_config($this->Locale); - } else { - return SiteConfig::current_site_config(); - } + + return SiteConfig::current_site_config(); } /**