Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

ModelAdmin mit PageTypes


Reply


2 Posts   402 Views

Avatar
sashion

Community Member, 23 Posts

18 August 2013 at 11:15pm

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

Avatar
ingermarie

Community Member, 1 Post

27 August 2013 at 11:57pm

Edited: 28/08/2013 12:04am

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:
[url]https://github.com/unclecheese/silverstripe-gridfield-betterbuttons[/url]

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):
[url]https://github.com/micschk/silverstripe-excludechildren[/url]