Created
December 1, 2021 03:23
-
-
Save jkersu/8502975a0265604ffe3625d622557885 to your computer and use it in GitHub Desktop.
Add a new button inside a Gridfield individual item for Silverstripe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
} | |
} |
Great example also!!! love it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be good to see what you need to return in the action.