mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Merge branch 'chillu-pulls/localized-urlsegment-creation' into 3
This commit is contained in:
commit
177ef7d99a
@ -15,7 +15,7 @@ class SiteTreeURLSegmentField extends TextField {
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $helpText, $urlPrefix, $urlSuffix;
|
||||
protected $helpText, $urlPrefix, $urlSuffix, $defaultUrl;
|
||||
|
||||
private static $allowed_actions = array(
|
||||
'suggest'
|
||||
@ -30,7 +30,8 @@ class SiteTreeURLSegmentField extends TextField {
|
||||
parent::getAttributes(),
|
||||
array(
|
||||
'data-prefix' => $this->getURLPrefix(),
|
||||
'data-suffix' => '?stage=Stage'
|
||||
'data-suffix' => '?stage=Stage',
|
||||
'data-default-url' => $this->getDefaultURL()
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -74,7 +75,8 @@ class SiteTreeURLSegmentField extends TextField {
|
||||
* @param string $string The secondary text to show
|
||||
*/
|
||||
public function setHelpText($string){
|
||||
$this->helpText = $string;
|
||||
$this->helpText = $string;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,6 +92,7 @@ class SiteTreeURLSegmentField extends TextField {
|
||||
*/
|
||||
public function setURLPrefix($url){
|
||||
$this->urlPrefix = $url;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,8 +106,23 @@ class SiteTreeURLSegmentField extends TextField {
|
||||
return $this->urlSuffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Indicator for UI to respond to changes accurately,
|
||||
* and auto-update the field value if changes to the default occur.
|
||||
* Does not set the field default value.
|
||||
*/
|
||||
public function getDefaultURL(){
|
||||
return $this->defaultUrl;
|
||||
}
|
||||
|
||||
public function setDefaultURL($url) {
|
||||
$this->defaultUrl = $url;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setURLSuffix($suffix) {
|
||||
$this->urlSuffix = $suffix;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function Type() {
|
||||
|
@ -1533,7 +1533,11 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
}
|
||||
|
||||
// If there is no URLSegment set, generate one from Title
|
||||
if((!$this->URLSegment || $this->URLSegment == 'new-page') && $this->Title) {
|
||||
$defaultSegment = $this->generateURLSegment(_t(
|
||||
'CMSMain.NEWPAGE',
|
||||
array('pagetype' => $this->i18n_singular_name())
|
||||
));
|
||||
if((!$this->URLSegment || $this->URLSegment == $defaultSegment) && $this->Title) {
|
||||
$this->URLSegment = $this->generateURLSegment($this->Title);
|
||||
} else if($this->isChanged('URLSegment', 2)) {
|
||||
// Do a strict check on change level, to avoid double encoding caused by
|
||||
@ -1971,8 +1975,12 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
(self::config()->nested_urls && $this->ParentID ? $this->Parent()->RelativeLink(true) : null)
|
||||
);
|
||||
|
||||
$urlsegment = new SiteTreeURLSegmentField("URLSegment", $this->fieldLabel('URLSegment'));
|
||||
$urlsegment->setURLPrefix($baseLink);
|
||||
$urlsegment = SiteTreeURLSegmentField::create("URLSegment", $this->fieldLabel('URLSegment'))
|
||||
->setURLPrefix($baseLink)
|
||||
->setDefaultURL($this->generateURLSegment(_t(
|
||||
'CMSMain.NEWPAGE',
|
||||
array('pagetype' => $this->i18n_singular_name())
|
||||
)));
|
||||
$helpText = (self::config()->nested_urls && count($this->Children())) ? $this->fieldLabel('LinkChangeNote') : '';
|
||||
if(!Config::inst()->get('URLSegmentFilter', 'default_allow_multibyte')) {
|
||||
$helpText .= $helpText ? '<br />' : '';
|
||||
|
@ -39,7 +39,10 @@
|
||||
self.data('OrigVal', title);
|
||||
|
||||
// Criteria for defining a "new" page
|
||||
if ((urlSegmentInput.val().indexOf('new') == 0) && liveLinkInput.val() == '') {
|
||||
if (
|
||||
urlSegmentInput.val().indexOf(urlSegmentInput.data('defaultUrl')) === 0
|
||||
&& liveLinkInput.val() == ''
|
||||
) {
|
||||
self.updateURLSegment(title);
|
||||
} else {
|
||||
$('.update', self.parent()).show();
|
||||
|
@ -406,8 +406,7 @@ class SiteTreeTest extends SapphireTest {
|
||||
Versioned::reading_stage('Stage');
|
||||
Config::inst()->update('SiteTree', 'enforce_strict_hierarchy', true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testDeleteFromLiveOperatesRecursivelyStrict() {
|
||||
$this->logInWithPermission('ADMIN');
|
||||
|
||||
@ -545,7 +544,7 @@ class SiteTreeTest extends SapphireTest {
|
||||
// Confirm that Member.editor can still edit the page
|
||||
$this->objFromFixture('Member','editor')->logIn();
|
||||
$this->assertTrue($page->canEdit());
|
||||
}
|
||||
}
|
||||
|
||||
public function testCompareVersions() {
|
||||
// Necessary to avoid
|
||||
@ -693,6 +692,59 @@ class SiteTreeTest extends SapphireTest {
|
||||
$this->assertTrue($ceo->isSection());
|
||||
}
|
||||
|
||||
public function testURLSegmentAutoUpdate() {
|
||||
$sitetree = new SiteTree();
|
||||
$sitetree->Title = _t(
|
||||
'CMSMain.NEWPAGE',
|
||||
array('pagetype' => $sitetree->i18n_singular_name())
|
||||
);
|
||||
$sitetree->write();
|
||||
$this->assertEquals($sitetree->URLSegment, 'new-page',
|
||||
'Sets based on default title on first save'
|
||||
);
|
||||
|
||||
$sitetree->Title = 'Changed';
|
||||
$sitetree->write();
|
||||
$this->assertEquals($sitetree->URLSegment, 'changed',
|
||||
'Auto-updates when set to default title'
|
||||
);
|
||||
|
||||
$sitetree->Title = 'Changed again';
|
||||
$sitetree->write();
|
||||
$this->assertEquals($sitetree->URLSegment, 'changed',
|
||||
'Does not auto-update once title has been changed'
|
||||
);
|
||||
}
|
||||
|
||||
public function testURLSegmentAutoUpdateLocalized() {
|
||||
$oldLocale = i18n::get_locale();
|
||||
i18n::set_locale('de_DE');
|
||||
|
||||
$sitetree = new SiteTree();
|
||||
$sitetree->Title = _t(
|
||||
'CMSMain.NEWPAGE',
|
||||
array('pagetype' => $sitetree->i18n_singular_name())
|
||||
);
|
||||
$sitetree->write();
|
||||
$this->assertEquals($sitetree->URLSegment, 'neue-seite',
|
||||
'Sets based on default title on first save'
|
||||
);
|
||||
|
||||
$sitetree->Title = 'Changed';
|
||||
$sitetree->write();
|
||||
$this->assertEquals($sitetree->URLSegment, 'changed',
|
||||
'Auto-updates when set to default title'
|
||||
);
|
||||
|
||||
$sitetree->Title = 'Changed again';
|
||||
$sitetree->write();
|
||||
$this->assertEquals($sitetree->URLSegment, 'changed',
|
||||
'Does not auto-update once title has been changed'
|
||||
);
|
||||
|
||||
i18n::set_locale($oldLocale);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers SiteTree::validURLSegment
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user