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.

All other Modules /

Discuss all other Modules here.

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

EventCalendar - Modifying Announcements


Reply


2 Posts   1010 Views

Avatar
silk

Community Member, 18 Posts

25 January 2010 at 2:52am

Hello,

I am expanding the EventCalendar a little bit and everything is working fine
as long I adapt the CalendarEvents (like adding a field to the database and adding appropriate elements in the CMS). For 90% of my events the announcement structure would be a better solution, though (small content and having all the good things from DataObjectManager). Now I want to tweak the announcements, too (again: like adding a field to the database and adding appropriate elements in the CMS with updateCMSFields).

Adding fields is no problem, using the SiteTreeDecorator-approach I added the fields to CalendarDateTime. Now I should be able to use them for CalendarEvents and Announcements. Neat! Now that I think about it, CalendarDateTime is a DataObject and no SiteTree Descendant, so this is not the correct way to do it, is it?

Now my main question:
Is there any way to change the CMS with something like updateCMSFields for the announcements as well?
I see there is a abstract function

extendAnnouncement

that seems to do something like this. So I have to derive from it? I'd love to have a way to do it with decorators, though.
What is the best way to do it?

Avatar
UncleCheese

4085 Posts

25 January 2010 at 4:10am

extendAnnouncement() is what you want. In your DateTime subclass:

public function extendAnnouncement() {
$this->addAnnouncementFields(array(
new TextField('SomeCustomField'),
new DropdownField('SomeRelationID','Choose related thing')
));

$this->addAnnouncementTitles(array(
'SomeCustomField' => 'Some custom title'
));
}

I thought for a long time about using decorators, but there were two main reasons why I opted not to do so:

1) Decorators are enigmatic and inaccessible to most Silverstripe programmers. There's little documentation on them, and it's just not as mainstream a practice as subclassing.

2) I didn't like the idea of making global alterations to the calendar/event/datetime models. I thought it was a viable scenario that one would have multiple calendars, each with different data models.