content management system - Adding a button to the CMS in SilverStripe -
How do I add a button in the backend of CMS which activates an action? I can display that button where I want to:
public function getCMSFields () {$ fields = parent :: getCMSFields (); $ Fields- & gt; AddFieldsToTab ("Root.ButtonTest", array (FormAction :: create ('doAction', 'Action button'))); Return $ field; } Public Function doAction () {// Something}
However, nothing is going on when the button is added.
How I have seen an example is not on the main action bar (next to save / publish) button which I am trying to do.
Only me can get it, I need to do something within it:
public function getCMSActions () {$ actions = parent :: getCMSActions (); // is something here? }
It is not very clear how the button calls.
With your own extension and the call you want to call, LeftAndMain
will have to be expanded / decorated. Here's an example:
& lt ;? Php class expanded to MyExtension Left & MainExtension {Private Stable $ permissions_rections = array ('doAction'); Public function doAction ($ data, $ variant) {$ className = $ this- & gt; Owner- & gt; Stat ('tree_class'); $ SQL_id = Convert :: Raw 2 SQL ($ data ['id']); $ Record = DataObject :: get_by_id ($ className, $ SQL_id); If (! $ Record ||! $ Record-> ID) {new SSHTPRPSpace_exation ("Bad record id #". (Int) $ data ['id'], 404); } // At this point you have a $ record, which is your page with which you can work! // This creates a message that cms $$ in this- & gt; Owner- & gt; Feedback-> add header ('x-status', crudelean code ('success message!')) Will appear; Return $ this- & gt; Owner- & gt; GetResponseNegotiator () - & gt; Give feedback ($ this-> owner- & gt; request); }}
Once you write an extension like this, you must add it to your mysite / _config and apply it to
: LeftAndMain
/ config .yml
LeftAndMain: Extension: - My Extension
This is your doAction
button is now actually Should do something!
Comments
Post a Comment