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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

ModelAdmin mit PageTypes


Go to End


2 Posts   767 Views

Avatar
sashion

Community Member, 25 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:
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