mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
API SiteTree->validURLSegment() prioritizes extension votes
Tri-state, use NULL to ignore the extension result
This commit is contained in:
parent
4bc942df76
commit
0c4b2f8157
@ -1588,20 +1588,20 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
}
|
||||
}
|
||||
|
||||
$existingPage = DataObject::get_one(
|
||||
'SiteTree',
|
||||
"\"URLSegment\" = '$this->URLSegment' $IDFilter $parentFilter"
|
||||
$votes = array_filter(
|
||||
(array)$this->extend('augmentValidURLSegment'),
|
||||
function($v) {return !is_null($v);}
|
||||
);
|
||||
if ($existingPage) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$votes = $this->extend('augmentValidURLSegment');
|
||||
if($votes) {
|
||||
return min($votes);
|
||||
}
|
||||
|
||||
return true;
|
||||
$existingPage = DataObject::get_one(
|
||||
'SiteTree',
|
||||
"\"URLSegment\" = '$this->URLSegment' $IDFilter $parentFilter"
|
||||
);
|
||||
|
||||
return !($existingPage);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,6 +4,7 @@
|
||||
* @subpackage tests
|
||||
*/
|
||||
class SiteTreeTest extends SapphireTest {
|
||||
|
||||
protected static $fixture_file = 'SiteTreeTest.yml';
|
||||
|
||||
protected $illegalExtensions = array(
|
||||
@ -700,6 +701,18 @@ class SiteTreeTest extends SapphireTest {
|
||||
$this->assertTrue($sitetree->validURLSegment(), 'Valid URLSegment values are allowed');
|
||||
}
|
||||
|
||||
public function testURLSegmentPrioritizesExtensionVotes() {
|
||||
$sitetree = new SiteTree();
|
||||
$sitetree->URLSegment = 'unique-segment';
|
||||
$this->assertTrue($sitetree->validURLSegment());
|
||||
|
||||
SiteTree::add_extension('SiteTreeTest_Extension');
|
||||
$sitetree = new SiteTree();
|
||||
$sitetree->URLSegment = 'unique-segment';
|
||||
$this->assertFalse($sitetree->validURLSegment());
|
||||
SiteTree::remove_extension('SiteTreeTest_Extension');
|
||||
}
|
||||
|
||||
public function testURLSegmentMultiByte() {
|
||||
$origAllow = Config::inst()->get('URLSegmentFilter', 'default_allow_multibyte');
|
||||
Config::inst()->update('URLSegmentFilter', 'default_allow_multibyte', true);
|
||||
@ -960,3 +973,11 @@ class SiteTreeTest_StageStatusInherit extends SiteTree implements TestOnly {
|
||||
return $flags;
|
||||
}
|
||||
}
|
||||
|
||||
class SiteTreeTest_Extension extends DataExtension implements TestOnly {
|
||||
|
||||
public function augmentValidURLSegment() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user