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.

Blog Module

Discuss the Blog Module.

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

Extending Blog Entries - Best Way?


Go to End
Reply

19 Posts   3295 Views

Avatar
DanStephenson

27 January 2010 at 4:44pm Community Member, 115 Posts

I am looking to extend the CMS for the blog entries. I want to allow a few more fields (like a header image for example) when the user enters a blog entry, and remove some of the fields normally associated with the "Page" type, as they don't apply to my blog.

I know it's best not to add these in the blog module, so that when it gets upgraded, I won't lose my changes. What is the best way to extend this module?

Avatar
Ku$h

28 January 2010 at 9:07pm Community Member, 14 Posts

I've need to do exactly the same thing, can anybody help us?

Avatar
Willr

28 January 2010 at 10:32pm Forum Moderator, 5511 Posts

The best way to extend module / core functionality is to use decorators. http://doc.silverstripe.org/doku.php?id=dataobjectdecorator

Dan, To answer your specific issue - you should be able to customize the CMS within a decorator by using the updateCMSFields() function. See http://doc.silverstripe.org/doku.php?id=dataobjectdecorator#modifying_cms_fields

Avatar
DanStephenson

31 January 2010 at 8:00pm (Last edited: 31 January 2010 8:17pm), Community Member, 115 Posts

Hi Willr,

That's all I needed to know. Where do I put my dataobjectdecorator code?

Avatar
Willr

31 January 2010 at 8:12pm Forum Moderator, 5511 Posts

You can create a new file in mysite/code/ for the decorator.

Avatar
DanStephenson

31 January 2010 at 8:17pm (Last edited: 31 January 2010 8:17pm), Community Member, 115 Posts

Can I remove fields/CMS tabs using the data decorator? If so, how (the documentation shows how to add fields only), and if not, what's the best way to do that?

Avatar
Willr

31 January 2010 at 8:22pm Forum Moderator, 5511 Posts

Yes, as it says on the dataobjectdecorator page you can define a updateCMSFields(&$fields) function. You should be able to then call any of the usual cmsfields functions - http://doc.silverstripe.org/doku.php?id=getcmsfields

http://doc.silverstripe.org/doku.php?id=dataobjectdecorator#modifying_cms_fields

Avatar
DanStephenson

31 January 2010 at 10:15pm (Last edited: 31 January 2010 10:26pm), Community Member, 115 Posts

Maybe I am doing it wrong, but I am trying to remove 2 tabs from my CMS for all blog entries, like this:

public function updateCMSFields(FieldSet &$fields) {
   $fields->removeByName("RightSidebar");
$fields->removeByName("LeftSidebar");
}

And nothing is happening. Can anyone tell me what I am doing wrong here?

Go to Top