Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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 76be14b
Author: Damian Mooyman <damian.mooyman@gmail.com>
Date:   Fri Aug 24 08:28:18 2012 +1200

    FIXED: Indentation

commit 715b603
Author: Damian Mooyman <damian.mooyman@gmail.com>
Date:   Fri Aug 24 08:25:14 2012 +1200

    FIXED: Coding style inconsistencies

commit 6395f90
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 aca242e
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
  • Loading branch information...
commit 02e95adb4c8e69e599d873e501d80bc85cb5495a 1 parent c847b55
@tractorcow tractorcow authored chillu committed
Showing with 24 additions and 64 deletions.
  1. +20 −56 code/model/SiteConfig.php
  2. +4 −8 code/model/SiteTree.php
View
76 code/model/SiteConfig.php
@@ -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 @@ function getCMSFields() {
$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 @@ function CMSEditLink() {
* 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');
- }
-
- if (!$siteConfig) $siteConfig = self::make_site_config($locale);
+ static function current_site_config() {
+ if ($siteConfig = DataObject::get_one('SiteConfig')) return $siteConfig;
- return $siteConfig;
+ return self::make_site_config();
}
-
+
/**
* Setup a default SiteConfig record if none exists
*/
@@ -191,39 +178,16 @@ function requireDefaultRecords() {
/**
* 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");
-
- 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;
- }
+ static function make_site_config() {
+ $config = SiteConfig::create();
+ $config->write();
+ return $config;
+ }
- $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
View
12 code/model/SiteTree.php
@@ -991,17 +991,13 @@ public function canDeleteFromLive($member = null) {
* 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();
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.