Jump to:

5542 Posts in 1739 Topics by 1225 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Remove page type from Create dropdown in CMS

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1495 Views
  • omarkohl
    Avatar
    Community Member
    30 Posts

    Remove page type from Create dropdown in CMS Link to this post

    Basically what I wanted to do is enable only 1 instance of a certain page type (BannerPage) in the site tree.

    Overloading the canCreate() function in the BannerPage class works fine but not if you don't reload the backend after creating or deleting a BannerPage. Apparently canCreate() is only checked once when the backend is loaded and without reloading it allows you to create several instances of the page or (after deleting) doesn't re-enable the creation (only after reloading).

    To overcome this problem I overrode the onBeforeWrite() function to exit() if an instance of BannerPage exists.

    This solves my problem because it is not possible to create more than one instance of BannerPage but has 2 disadvantages:

    1. After deleting the only instance of BannerPage no new instance can be created except after reloading the backend
    2. No error message is shown to the user when trying to create more BannerPages (it simply doesn't work no matter how often you click) and this might be a little confusing (for him/her)

    Anyone has a better solution for this?

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Remove page type from Create dropdown in CMS Link to this post

    I would control it by having any required data for the page stored else where and then creating it as a hidden page... that is loaded based on a director rule.

    _config.php

    Director::addRules(100,array(
    'myonetimepage' => 'MyOneTimePage_Controller',
    ));

    class MyOneTimePage extends Page implements HiddenClass {}
    class MyOneTimePage_Controller extends Page_Controller {
       //stuff
    }

  • omarkohl
    Avatar
    Community Member
    30 Posts

    Re: Remove page type from Create dropdown in CMS Link to this post

    I'm asuming that HiddenClass hides the Page in the Site tree right? This is not what I need because the user has to be able to edit the content of this BannerPage.

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Remove page type from Create dropdown in CMS Link to this post

    Fine with me, just prompting a very clean option for hiding a page from the site tree.

    And please note I did say "any required data for the page stored else where" the site tree is very slow and not the right place for a lot of the information people store there. For my "system pages" as I call them I have one data object with the options in it editable via ModelAdmin or it can be linked to another page.

  • omarkohl
    Avatar
    Community Member
    30 Posts

    Re: Remove page type from Create dropdown in CMS Link to this post

    Actually BannerPage is never displayed in the frontend. It is just a "Data-Store" for Banners which are then displayed on several pages according to different rules.

    Maybe it would make more sense to convert the whole thing to a DataObject instead (because it has nothing to do with a page after all). The reason I did it this way is to have somewhere to edit those Banners. I thought about making it a Tab on some other page but somehow it seemed not right and the separation was clearer when creating a single separate Page just for this.

    So reformulating the whole question: How would you do this? Have a "Data-Store" to save all banners and information such as click-rate, etc. and a place to edit those banners. The main point is to make it for the whole site, not just for a single page, because Banners can be displayed anywhere and the data gathered is displayed in a backend report.

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts
  • omarkohl
    Avatar
    Community Member
    30 Posts

    Re: Remove page type from Create dropdown in CMS Link to this post

    Great! :-D That looks pretty much like what I'm looking for.

    Thanks!

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Remove page type from Create dropdown in CMS Link to this post

    You are very welcome - to me ModelAdmin is an amazing feature of ss. However I am very curious about ss v3 UI updates as when Ingo says "people know their datamodel and are willing to compromise on UI" in that presentation - I wish the folks I dealt with would...

    1495 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.