diff --git a/.travis.yml b/.travis.yml index bb1aba1..d1c7b33 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,19 +3,17 @@ language: php php: - - 5.3 + - 5.6 env: - DB=MYSQL CORE_RELEASE=3 matrix: include: - - php: 5.4 + - php: 5.6 env: DB=PGSQL CORE_RELEASE=3 - - php: 5.5 - env: DB=MYSQL CORE_RELEASE=3.2 - php: 5.6 - env: DB=MYSQL CORE_RELEASE=3.2 + env: DB=MYSQL CORE_RELEASE=3 before_script: - pear -q install --onlyreqdeps pear/PHP_CodeSniffer diff --git a/code/forms/LanguageDropdownField.php b/code/forms/LanguageDropdownField.php index d81a1b8..a385fd8 100755 --- a/code/forms/LanguageDropdownField.php +++ b/code/forms/LanguageDropdownField.php @@ -21,7 +21,7 @@ class LanguageDropdownField extends GroupedDropdownField { * @param string $list Indicates the source language list. * Can be either Common-English, Common-Native, Locale-English, Locale-Native */ - function __construct($name, $title, $excludeLocales = array(), + public function __construct($name, $title = null, $excludeLocales = array(), $translatingClass = 'SiteTree', $list = 'Common-English', $instance = null ) { $usedLocalesWithTitle = Translatable::get_existing_content_languages($translatingClass); diff --git a/code/model/Translatable.php b/code/model/Translatable.php index 0a4456c..6d83c06 100755 --- a/code/model/Translatable.php +++ b/code/model/Translatable.php @@ -743,7 +743,12 @@ public function requireDefaultRecords() { if(!$obj || $obj->ObsoleteClassName) continue; $obj->Locale = Translatable::default_locale(); - $obj->writeToStage($stage); + + $oldMode = Versioned::get_reading_mode(); + Versioned::reading_stage($stage); + $obj->writeWithoutVersion(); + Versioned::set_reading_mode($oldMode); + $obj->addTranslationGroup($obj->ID); $obj->destroy(); unset($obj); @@ -932,7 +937,7 @@ class_exists('SiteTree') $fresh = Versioned::get_one_by_stage( $baseDataClass, Versioned::current_stage(), - '"ID" = ' . $this->owner->ID, + '"'.$baseDataClass.'"."ID" = ' . $this->owner->ID, null ); if ($fresh) { @@ -1065,72 +1070,74 @@ function updateCMSFields(FieldList $fields) { $alreadyTranslatedLocales[$this->owner->Locale] = $this->owner->Locale; $alreadyTranslatedLocales = array_combine($alreadyTranslatedLocales, $alreadyTranslatedLocales); - // Check if fields exist already to avoid adding them twice on repeat invocations - $tab = $fields->findOrMakeTab('Root.Translations', _t('Translatable.TRANSLATIONS', 'Translations')); - if(!$tab->fieldByName('CreateTransHeader')) { - $tab->push(new HeaderField( - 'CreateTransHeader', - _t('Translatable.CREATE', 'Create new translation'), - 2 - )); - } - if(!$tab->fieldByName('NewTransLang') && !$tab->fieldByName('AllTransCreated')) { - $langDropdown = LanguageDropdownField::create( - "NewTransLang", - _t('Translatable.NEWLANGUAGE', 'New language'), - $alreadyTranslatedLocales, - 'SiteTree', - 'Locale-English', - $this->owner - )->addExtraClass('languageDropdown no-change-track'); - $tab->push($langDropdown); - $canAddLocale = (count($langDropdown->getSource()) > 0); - - if($canAddLocale) { - // Only add create button if new languages are available - $tab->push( - $createButton = InlineFormAction::create( - 'createtranslation', - _t('Translatable.CREATEBUTTON', 'Create') - )->addExtraClass('createTranslationButton') - ); - $createButton->includeDefaultJS(false); // not fluent API... - } else { - $tab->removeByName('NewTransLang'); - $tab->push(new LiteralField( - 'AllTransCreated', - _t('Translatable.ALLCREATED', 'All allowed translations have been created.') - )); - } - } - if($alreadyTranslatedLocales) { - if(!$tab->fieldByName('ExistingTransHeader')) { + if ($fields->hasTabSet()) { + // Check if fields exist already to avoid adding them twice on repeat invocations + $tab = $fields->findOrMakeTab('Root.Translations', _t('Translatable.TRANSLATIONS', 'Translations')); + if(!$tab->fieldByName('CreateTransHeader')) { $tab->push(new HeaderField( - 'ExistingTransHeader', - _t('Translatable.EXISTING', 'Existing translations'), - 3 + 'CreateTransHeader', + _t('Translatable.CREATE', 'Create new translation'), + 2 )); - if (!$tab->fieldByName('existingtrans')) { - $existingTransHTML = ''; - $tab->push(new LiteralField('existingtrans', $existingTransHTML)); } } - } + } } function updateSettingsFields(&$fields) { @@ -1572,15 +1579,15 @@ function AllChildrenIncludingDeleted($context = null) { function MetaTags(&$tags) { $template = '' . "\n"; $translations = $this->owner->getTranslations(); - if($translations) { + if($translations->count()) { $translations = $translations->toArray(); $translations[] = $this->owner; - - foreach($translations as $translation) { - $tags .= sprintf($template, - Convert::raw2xml($translation->Title), - i18n::convert_rfc1766($translation->Locale), - $translation->AbsoluteLink() + + foreach($translations as $translation) { + $tags .= sprintf($template, + Convert::raw2xml($translation->Title), + i18n::convert_rfc1766($translation->Locale), + $translation->AbsoluteLink() ); } } @@ -1766,7 +1773,7 @@ static function set_reading_lang($lang) { * @deprecated 2.4 Use get_reading_locale() */ static function get_reading_lang() { - return i18n::get_lang_from_locale(self::get_reading_locale()); + return i18n::get_lang_from_locale(self::get_current_locale()); } /** diff --git a/tests/unit/TranslatableSiteConfigTest.php b/tests/unit/TranslatableSiteConfigTest.php index 3476613..fd6081d 100644 --- a/tests/unit/TranslatableSiteConfigTest.php +++ b/tests/unit/TranslatableSiteConfigTest.php @@ -22,6 +22,9 @@ function setUp() { $this->origLocale = Translatable::default_locale(); Translatable::set_default_locale("en_US"); + + // Delete any default records created outside of fixtures + SiteConfig::get()->exclude('ID', $this->allFixtureIDs('SiteConfig'))->removeAll(); } function tearDown() {