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.

Customising the CMS /

How to add buttons and actions to the CMS


Reply


3 Posts   396 Views

Avatar
Peavers

Community Member, 12 Posts

30 April 2014 at 8:54am

Edited: 30/04/2014 8:55am

How do I go about adding a button to the backend of the CMS?

I can display the button where I want using:

public function getCMSFields()
{
$fields = parent::getCMSFields();

$fields->addFieldsToTab("Root.ButtonTest", array(
FormAction::create('doAction', 'Action button')
)
);

return $fields;
}

public function doAction()
{
//Do something
}

However, doAction does nothing when the button is clicked.

I've seen one example of how to put a button on the main action bar (Next to save/publish) but thats not what I'm trying to do.

Looking at the only documentation page I can find, do I need to do something within

public function getCMSActions()
{
$actions = parent::getCMSActions();
//Something here?
}

I can't find any clear documentation on how to handle the button action.

Note: Same question on SO if you want the rep https://stackoverflow.com/questions/23353998/adding-button-to-silverstripe-cms

Avatar
Peavers

Community Member, 12 Posts

6 May 2014 at 9:26am

Core framework needs some work if its so complicated to add a simple button and action that nobody has a clue how to do it eh?

Avatar
camfindlay

Forum Moderator, 203 Posts

6 May 2014 at 12:53pm

Can you perhaps provide some more insight into the outcome you are trying to get here?

What are you building?, where do you want this button to appear and what do you want to happen when it is clicked? From what I know, FormAction is designed to create a button which submits a form, rather than a stand alone button that will just trigger a php method to run.

Give some context to your question :)