Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » ModelAdmin mit PageTypes

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

Page: 1
Go to End
Author Topic: 243 Views
  • sashion
    Avatar
    Community Member
    21 Posts

    ModelAdmin mit PageTypes Link to this post

    Hey guys,

    i want to handle all my newsPages in the ModelAdmin of SS3. The news are extended from Page and not DataObject.
    I just created a ModelAdmin and also can see all my NewsPages there. i also defined that one newsPage can have only one newsHolder and a newsHolder can have many newsPages.

    There are two problem right now:
    - is if I create a new newsPAge in tehe modeladmin and save it, it is still unpublished and doesn´t show up on the wbesite.
    - the other problem is that there is nothing where i can choose the place for the newspage to be. i would expect a dropdown where i can select all availabe newsHolders or something like that.

    Any ideas?

    Thanks in advance,
    sash

  • ingermarie
    Avatar
    Community Member
    1 Post

    Re: ModelAdmin mit PageTypes Link to this post

    Hi!
    Please correct me if better solutions are available. The code below is what worked for me.

    Save and publish should be available from betterbuttons for gridfield:
    https://github.com/unclecheese/silverstripe-gridfield-betterbuttons

    This is the solution I found to place the NewsPages under the NewsHolder:

    function onAfterWrite(){
       $parentID = DataObject::get_one('NewsHolder')->ID;
       if($this->ParentID != $parentID)
       {
          $this->ParentID = $parentID;
          $this->write();
       }
       parent::onAfterWrite();
    }

    Disables creating more than one NewsHolder (recommended):

    public function canCreate() {
       return DataObject::get_one('NewsHolder') ? false : true;
    }

    I chose to hide NewsHolder from SiteTree by adding css class to NewsHolder in SiteTree (and hiding .nositetree with css):

    public function CMSTreeClasses() {
       return parent::CMSTreeClasses() . ' nositetree';
    }

    Hiding NewsPages from NewsHolder in SiteTree (optional):
    https://github.com/micschk/silverstripe-excludechildren

    243 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.