Skip to content

Commit

Permalink
FIX: put current page on top of ClassName dropdown (was broken)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnysideup committed Sep 13, 2024
1 parent df5a779 commit 7272472
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions code/Model/SiteTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -2744,8 +2744,6 @@ public function isNew()
protected function getClassDropdown()
{
$classes = SiteTree::page_type_classes();
$currentClass = null;

$result = [];
foreach ($classes as $class) {
$instance = singleton($class);
Expand All @@ -2771,20 +2769,15 @@ protected function getClassDropdown()
}
}

$pageTypeName = $instance->i18n_singular_name();

$currentClass = $class;
$result[$class] = $pageTypeName;
$result[$class] = $instance->i18n_singular_name();
}

// sort alphabetically, and put current on top
// Sort alphabetically, and put current on top
asort($result);
if ($currentClass) {
$currentPageTypeName = $result[$currentClass];
unset($result[$currentClass]);
$result = array_reverse($result ?? []);
$result[$currentClass] = $currentPageTypeName;
$result = array_reverse($result ?? []);
if (isset($result[$this->ClassName])) {
$currentPageTypeName = $result[$this->ClassName];
unset($result[$this->ClassName]);
$result = [$this->ClassName => $currentPageTypeName] + $result;
}

return $result;
Expand Down

0 comments on commit 7272472

Please sign in to comment.