mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 09:05:53 +00:00
BUG Consistently save SiteConfig, and refactor Translatable hooks
Squashed commit of the following: commit a60eddfacc710d3047bd1d5107e5df0cc6dba93c Merge: c847b55 76be14b Author: Ingo Schommer <ingo@silverstripe.com> Date: Fri Sep 7 17:02:47 2012 +0200 Merge branch '3.0-translation-migration' of git://github.com/tractorcow/silverstripe-cms into tractorcow-3.0-translation-migration commit 76be14b1fccc05b5dcca8c805e0354a42e75135d Author: Damian Mooyman <damian.mooyman@gmail.com> Date: Fri Aug 24 08:28:18 2012 +1200 FIXED: Indentation commit 715b60387c970846db1bf9a5f14140aee49ce665 Author: Damian Mooyman <damian.mooyman@gmail.com> Date: Fri Aug 24 08:25:14 2012 +1200 FIXED: Coding style inconsistencies commit 6395f9030ed65b24494842ce74864ff7ebbf6c5e Author: Damian Mooyman <damian.mooyman@gmail.com> Date: Thu Aug 16 16:30:11 2012 +1200 FIXED: Issue where new SiteConfig instances weren't always saved to the database commit aca242e31c8d98ee3b8acc397bf605ceb964e1bf Author: Damian Mooyman <damian.mooyman@gmail.com> Date: Thu Aug 16 14:22:56 2012 +1200 UPDATED: Refactored Translation module specific code out of the SiteConfig
This commit is contained in:
parent
c847b55608
commit
02e95adb4c
@ -1,15 +1,8 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Sitewide configuration.
|
||||
*
|
||||
* h2. Translation
|
||||
*
|
||||
* To enable translation of configurations alongside the {@link Translatable} extension.
|
||||
* This also allows assigning language-specific toplevel permissions for viewing and editing
|
||||
* pages, in addition to the normal `TRANSLATE_*`/`TRANSLATE_ALL` permissions.
|
||||
*
|
||||
* Object::add_extension('SiteConfig', 'Translatable');
|
||||
*
|
||||
* @author Tom Rix
|
||||
* @package cms
|
||||
*/
|
||||
@ -34,7 +27,16 @@ class SiteConfig extends DataObject implements PermissionProvider {
|
||||
public static function disable_theme($theme) {
|
||||
self::$disabled_themes[$theme] = $theme;
|
||||
}
|
||||
|
||||
|
||||
function populateDefaults()
|
||||
{
|
||||
$this->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
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user