mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 06:05:56 +00:00
Compare commits
2 Commits
0307fa6cb0
...
4be3523a2c
Author | SHA1 | Date | |
---|---|---|---|
|
4be3523a2c | ||
|
a9ed7b986f |
@ -2747,6 +2747,8 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
|
|||||||
protected function getClassDropdown()
|
protected function getClassDropdown()
|
||||||
{
|
{
|
||||||
$classes = SiteTree::page_type_classes();
|
$classes = SiteTree::page_type_classes();
|
||||||
|
$currentClass = null;
|
||||||
|
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach ($classes as $class) {
|
foreach ($classes as $class) {
|
||||||
$instance = singleton($class);
|
$instance = singleton($class);
|
||||||
@ -2772,15 +2774,20 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$result[$class] = $instance->i18n_singular_name();
|
$pageTypeName = $instance->i18n_singular_name();
|
||||||
|
|
||||||
|
$currentClass = $class;
|
||||||
|
$result[$class] = $pageTypeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort alphabetically, and put current on top
|
// sort alphabetically, and put current on top
|
||||||
asort($result);
|
asort($result);
|
||||||
if (isset($result[$this->ClassName])) {
|
if ($currentClass) {
|
||||||
$currentPageTypeName = $result[$this->ClassName];
|
$currentPageTypeName = $result[$currentClass];
|
||||||
unset($result[$this->ClassName]);
|
unset($result[$currentClass]);
|
||||||
$result = [$this->ClassName => $currentPageTypeName] + $result;
|
$result = array_reverse($result ?? []);
|
||||||
|
$result[$currentClass] = $currentPageTypeName;
|
||||||
|
$result = array_reverse($result ?? []);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -1272,7 +1272,7 @@ class SiteTreeTest extends SapphireTest
|
|||||||
#[DataProvider('allowedChildrenProvider')]
|
#[DataProvider('allowedChildrenProvider')]
|
||||||
public function testAllowedChildren($className, $expected, $assertionMessage)
|
public function testAllowedChildren($className, $expected, $assertionMessage)
|
||||||
{
|
{
|
||||||
$class = new $className();
|
$class = new $className;
|
||||||
$this->assertEquals($expected, $class->allowedChildren(), $assertionMessage);
|
$this->assertEquals($expected, $class->allowedChildren(), $assertionMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1351,9 +1351,6 @@ class SiteTreeTest extends SapphireTest
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testClassDropdown()
|
public function testClassDropdown()
|
||||||
{
|
{
|
||||||
$sitetree = new SiteTree();
|
$sitetree = new SiteTree();
|
||||||
@ -1375,18 +1372,7 @@ class SiteTreeTest extends SapphireTest
|
|||||||
|
|
||||||
$this->assertArrayNotHasKey(SiteTreeTest_NotRoot::class, $method->invoke($rootPage));
|
$this->assertArrayNotHasKey(SiteTreeTest_NotRoot::class, $method->invoke($rootPage));
|
||||||
$this->assertArrayHasKey(SiteTreeTest_NotRoot::class, $method->invoke($nonRootPage));
|
$this->assertArrayHasKey(SiteTreeTest_NotRoot::class, $method->invoke($nonRootPage));
|
||||||
foreach ([SiteTreeTest_ClassA::class, SiteTreeTest_ClassB::class] as $className) {
|
|
||||||
$otherPage = new $className();
|
|
||||||
$otherPage->write();
|
|
||||||
$result = $method->invoke(object: $otherPage);
|
|
||||||
$this->assertEquals(array_key_first($result), $className);
|
|
||||||
// remove the first element as this is not alphabetical
|
|
||||||
array_shift($result);
|
|
||||||
// create a sorted array
|
|
||||||
$resultSorted = $result;
|
|
||||||
asort($resultSorted);
|
|
||||||
$this->assertEquals($result, $resultSorted);
|
|
||||||
}
|
|
||||||
Security::setCurrentUser(null);
|
Security::setCurrentUser(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user