BUG Honour URL suffix on URL Segment field

This commit is contained in:
Maxime Rainville 2020-08-06 14:23:58 +12:00
parent 65b8cc3948
commit 31fa262475
3 changed files with 33 additions and 1 deletions

View File

@ -53,7 +53,7 @@ class SiteTreeURLSegmentField extends TextField
parent::getAttributes(),
[
'data-prefix' => $this->getURLPrefix(),
'data-suffix' => '?stage=Stage',
'data-suffix' => $this->getURLSuffix(),
'data-default-url' => $this->getDefaultURL()
]
);

View File

@ -2027,6 +2027,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$urlsegment = SiteTreeURLSegmentField::create("URLSegment", $this->fieldLabel('URLSegment'))
->setURLPrefix($baseLink)
->setURLSuffix('?stage=Stage')
->setDefaultURL($this->generateURLSegment(_t(
'SilverStripe\\CMS\\Controllers\\CMSMain.NEWPAGE',
'New {pagetype}',

View File

@ -0,0 +1,31 @@
<?php
namespace SilverStripe\CMS\Tests\Controllers;
use SilverStripe\CMS\BatchActions\CMSBatchAction_Archive;
use SilverStripe\CMS\BatchActions\CMSBatchAction_Publish;
use SilverStripe\CMS\BatchActions\CMSBatchAction_Restore;
use SilverStripe\CMS\BatchActions\CMSBatchAction_Unpublish;
use SilverStripe\CMS\Forms\SiteTreeURLSegmentField;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Versioned\Versioned;
/**
* Tests CMS Specific subclasses of {@see CMSBatchAction}
*/
class SiteTreeURLSegmentFieldTest extends SapphireTest
{
/**
* Test which pages can be published via batch actions
*/
public function testURLSuffix()
{
$field = new SiteTreeURLSegmentField('URLSegment');
$field->setURLSuffix('?foo=bar');
$this->assertEquals('?foo=bar', $field->getURLSuffix());
$this->assertEquals('?foo=bar', $field->getAttributes()['data-suffix']);
}
}