Skip to content

Instantly share code, notes, and snippets.

@jkersu
Created December 1, 2021 03:26
Show Gist options
  • Save jkersu/f7ae8bdacb7a7178662ca2701c355167 to your computer and use it in GitHub Desktop.
Save jkersu/f7ae8bdacb7a7178662ca2701c355167 to your computer and use it in GitHub Desktop.
Add a button to a Silverstripe Page in the CMS
// Add an extension to SilverStripe\Admin\LeftAndMain
class LeftAndMainExtension extends Extension
{
public function someFancyAction($data, $form)
{
// do some fancy stuff
}
}
// Add to your PageType class where you want the button
public function getCMSActions()
{
$actions = parent::getCMSActions();
$buttons = $actions->fieldByName('MajorActions');
$buttons->push($newFields = FormAction::create('someFancyAction', 'Do Action'));
$newFields ->addExtraClass('btn-outline-primary font-icon-tick')
->setUseButtonTag(true);
return $actions;
}
@sunnysideup
Copy link

It would be good to see what you need to return in the action.

@sunnysideup
Copy link

Great example also!!! love it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment