mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX: Fix #5097, Translatable uses augmentValidURLSegment to check that URLSegment is valid
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@99850 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
5531e01a69
commit
be26cf2579
@ -1152,6 +1152,14 @@ class Translatable extends DataObjectDecorator implements PermissionProvider {
|
||||
|
||||
$newTranslation->ID = 0;
|
||||
$newTranslation->Locale = $locale;
|
||||
|
||||
$originalPage = $this->getTranslation(self::default_locale());
|
||||
if ($originalPage) {
|
||||
$urlSegment = $originalPage->URLSegment;
|
||||
} else {
|
||||
$urlSegment = $newTranslation->URLSegment;
|
||||
}
|
||||
$newTranslation->URLSegment = $urlSegment . '-' . i18n::convert_rfc1766($locale);
|
||||
// hacky way to set an existing translation group in onAfterWrite()
|
||||
$translationGroupID = $this->getTranslationGroup();
|
||||
$newTranslation->_TranslationGroupID = $translationGroupID ? $translationGroupID : $this->owner->ID;
|
||||
@ -1453,6 +1461,39 @@ class Translatable extends DataObjectDecorator implements PermissionProvider {
|
||||
function cacheKeyComponent() {
|
||||
return 'locale-'.self::get_current_locale();
|
||||
}
|
||||
|
||||
/**
|
||||
* Extends the SiteTree::validURLSegment() method, to do checks appropriate
|
||||
* to Translatable
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function augmentValidURLSegment() {
|
||||
if (self::locale_filter_enabled()) {
|
||||
self::disable_locale_filter();
|
||||
$reEnableFilter = true;
|
||||
}
|
||||
$IDFilter = ($this->owner->ID) ? "AND \"SiteTree\".\"ID\" <> {$this->owner->ID}" : null;
|
||||
$parentFilter = null;
|
||||
|
||||
if(SiteTree::nested_urls()) {
|
||||
if($this->owner->ParentID) {
|
||||
$parentFilter = " AND \"SiteTree\".\"ParentID\" = {$this->owner->ParentID}";
|
||||
} else {
|
||||
$parentFilter = ' AND "SiteTree"."ParentID" = 0';
|
||||
}
|
||||
}
|
||||
|
||||
$existingPage = DataObject::get_one(
|
||||
'SiteTree',
|
||||
"\"URLSegment\" = '{$this->owner->URLSegment}' $IDFilter $parentFilter",
|
||||
false // disable get_one cache, as this otherwise may pick up results from when locale_filter was on
|
||||
);
|
||||
if ($reEnableFilter) {
|
||||
self::enable_locale_filter();
|
||||
}
|
||||
return !$existingPage;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -173,6 +173,8 @@ class TranslatableTest extends FunctionalTest {
|
||||
function testTranslationCantHaveSameURLSegmentAcrossLanguages() {
|
||||
$origPage = $this->objFromFixture('Page', 'testpage_en');
|
||||
$translatedPage = $origPage->createTranslation('de_DE');
|
||||
$this->assertEquals($translatedPage->URLSegment, 'testpage-de-DE');
|
||||
|
||||
$translatedPage->URLSegment = 'testpage';
|
||||
$translatedPage->write();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user