mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX Fixed TranslatableTest URLSegment detection
BUGFIX Removed URLSegment detection from Translatable->onBeforeWrite() - it was always preceeded by SiteTree->onBeforeWrite() which already alters the URL, so the appending of locale values to disambiguate the URL was pointless (never triggered) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@75983 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
984efd8ddf
commit
3fcb2a336a
@ -634,6 +634,10 @@ class Translatable extends DataObjectDecorator {
|
||||
* nested pages accessible in a translated CMS page tree.
|
||||
* It would be more userfriendly to grey out untranslated pages,
|
||||
* but this involves complicated special cases in AllChildrenIncludingDeleted().
|
||||
*
|
||||
* {@link SiteTree->onBeforeWrite()} will ensure that each translation will get
|
||||
* a unique URL across languages, by means of {@link SiteTree::get_by_url()}
|
||||
* and {@link Translatable->alternateGetByURL()}.
|
||||
*/
|
||||
function onBeforeWrite() {
|
||||
// If language is not set explicitly, set it to current_locale.
|
||||
@ -661,18 +665,6 @@ class Translatable extends DataObjectDecorator {
|
||||
}
|
||||
}
|
||||
|
||||
// Specific logic for SiteTree subclasses.
|
||||
// Append language to URLSegment to disambiguate URLs, meaning "myfrenchpage"
|
||||
// will save as "myfrenchpage-fr" (only if we're not in the "default language").
|
||||
// Its bad SEO to have multiple resources with different content (=language) under the same URL.
|
||||
if($this->owner->hasField('URLSegment')) {
|
||||
if(!$this->owner->ID && $this->owner->Locale != Translatable::default_locale()) {
|
||||
$SQL_URLSegment = Convert::raw2sql($this->owner->URLSegment);
|
||||
$existingOriginalPage = Translatable::get_one_by_lang('SiteTree', Translatable::default_locale(), "\"URLSegment\" = '{$SQL_URLSegment}'");
|
||||
if($existingOriginalPage) $this->owner->URLSegment .= "-{$this->owner->Locale}";
|
||||
}
|
||||
}
|
||||
|
||||
// Has to be limited to the default locale, the assumption is that the "page type"
|
||||
// dropdown is readonly on all translations.
|
||||
if($this->owner->ID && $this->owner->Locale == Translatable::default_locale()) {
|
||||
|
@ -174,12 +174,13 @@ class TranslatableTest extends FunctionalTest {
|
||||
);
|
||||
}
|
||||
|
||||
function testTranslationCanHaveSameURLSegment() {
|
||||
function testTranslationCantHaveSameURLSegmentAcrossLanguages() {
|
||||
$origPage = $this->objFromFixture('Page', 'testpage_en');
|
||||
$translatedPage = $origPage->createTranslation('de_DE');
|
||||
$translatedPage->URLSegment = 'testpage';
|
||||
$translatedPage->write();
|
||||
|
||||
$this->assertEquals($origPage->URLSegment, $translatedPage->URLSegment);
|
||||
$this->assertNotEquals($origPage->URLSegment, $translatedPage->URLSegment);
|
||||
}
|
||||
|
||||
function testUpdateCMSFieldsOnSiteTree() {
|
||||
|
Loading…
Reference in New Issue
Block a user