Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Cutom Save in CMS

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

Page: 1
Go to End
Author Topic: 1854 Views
  • digitalegg
    Avatar
    Community Member
    7 Posts

    Cutom Save in CMS Link to this post

    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

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: Cutom Save in CMS Link to this post

    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

  • digitalegg
    Avatar
    Community Member
    7 Posts

    Re: Cutom Save in CMS Link to this post

    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

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: Cutom Save in CMS Link to this post

    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

  • digitalegg
    Avatar
    Community Member
    7 Posts

    Re: Cutom Save in CMS Link to this post

    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

    1854 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.