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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

Cutom Save in CMS


Go to End


5 Posts   3468 Views

Avatar
digitalegg

Community Member, 7 Posts

28 March 2009 at 6:02am

Edited: 28/03/2009 6:03am

Hi,

I am new to Silverstripe (which is amazing btw) so sorry if this has an obvious answer :)

Is there a way to override the Save event in the admin CMS?

What I am trying to do is save multiple records to the database at the same time.

So I have 2 date fields, StartDate & EndDate (+ some other fields)

What I want to do is loop through the dates and add/edit entries depending on the date range. For example if I choose:

2009-03-27 - 2009-03-31

It would save 5 records to the database.

I can write the function to do this no problem, but how do I get it to be called when I click the 'Save' button?

Hope this makes sense.

Cheers

Mike

Avatar
Ben Gribaudo

Community Member, 181 Posts

28 March 2009 at 10:35am

Hi Mike,

Classes inheriting from DataObject (which includes Page), have several "on" events, including onBeforeWrite() and onAfterWrite(), which you can override.

More details: http://doc.silverstripe.com/doku.php?id=datamodel#onbeforewrite

Hope this helps!
Ben

Avatar
digitalegg

Community Member, 7 Posts

28 March 2009 at 11:04am

Hi Ben,

Thanks for the tip, I will check them out.

I actually found an interesting function which adds a custom submit button to the CMS...

function getCMSActions() {
return new FormAction(
'bulkUpdate',
'Bulk Update'
);
}

But I can't quite work out how/where I need to put the bulkUpdate function.

Any ideas?

Cheers

Mike

Avatar
Ben Gribaudo

Community Member, 181 Posts

31 March 2009 at 8:17am

Hi Mike,

I'm going to guess that bulkUpdate would go as an action in your controller, but I'm not sure as I've not worked much with FormAction. Have you looked at how FormAction is used in the core files? You might find some clues there.

Ben

Avatar
digitalegg

Community Member, 7 Posts

31 March 2009 at 8:26am

Hi Bn,

Thanks again for your reply :)

I dug a bit more and have decided to use the onBeforeSave method on the normal save button. So when a user clicks that I have a function which executes.

I will look at the FormAction some more later as it looks like maybe a better way to do it.

Cheers

Mike