Skip to content

Instantly share code, notes, and snippets.

@jkersu
Created December 1, 2021 03:23
Show Gist options
  • Save jkersu/8502975a0265604ffe3625d622557885 to your computer and use it in GitHub Desktop.
Save jkersu/8502975a0265604ffe3625d622557885 to your computer and use it in GitHub Desktop.
Add a new button inside a Gridfield individual item for Silverstripe
// Create an extension attached to: SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest
class GridFieldDetailFormItemRequestExtension extends Extension
{
public function updateFormActions(FieldList $actions)
{
$record = $this->owner->getRecord();
// This extension would run on every GridFieldDetailForm, so ensure you ignore contexts where
// you are managing a DataObject you don't care about
if ((!$record instanceof FOO || !$record->exists()) {
return;
}
if ($record instanceof FOO) {
$actions->insertBefore(
FormAction::create('doYourAwesomeAction', 'Awesome Action')
->setUseButtonTag(true)
->addExtraClass('btn action btn-info font-icon-p-news-item'),
'action_doDelete'
);
}
}
public function doYourAwesomeAction($data, $form)
{
// whatever your button needs to do
}
}
@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