4

Is there a way to sort the list of pages in the create page menu by a custom order (instead of alphabetically ie).

I'm looking for a solution similar to the way ModelAdmin menu items are ordered:

private static $menu_priority = 2;

enter image description here

Semicolon
  • 1,904
  • 14
  • 26

1 Answers1

2

Currently not, cause it's hardcoded to sort by "Singular Name", see https://github.com/silverstripe/silverstripe-cms/blob/3.5/code/controllers/CMSMain.php#L493

Nevertheless you could subclass CMSMain class, overwrite the method PageTypes() and tell SilverStripe to use your subclass instead of the original with an Injector.

E.g.:

class CustomCMSMain extends CMSMain {

    public function init() {
        parent::init(); //set a breakpoint here to prove this class is called
    }

    public function PageTypes() {
        //do something
    }
}

and in your config.yml

Injector:
  CMSMain:
    class: CustomCMSMain 

After a flush SilverStripe should use your own class which you can easily verify by setting a xdebug breakpoint in your own class, e.g. in the init method.

See docs for injector

wmk
  • 4,598
  • 1
  • 20
  • 37
  • Are you sure this it's possible to tell SS to use my subclass and method insteead of the original? I've been reading on the topic of using Injector to override core class / methods (for 2 days now) and most things tend to lean towards stating that it's not possible.. – Semicolon Dec 17 '16 at 15:45
  • It's possible if the class is instanciated using ::create() which should be the case for built in methods. – wmk Dec 19 '16 at 08:58
  • Thank you for the code example, unfortunately it gives the same effect as my attempt. It merely splits up the Pages section in two similar and disfunctional pages. – Semicolon Dec 19 '16 at 17:28