Last active
October 25, 2019 16:02
-
-
Save briceburg/15723ad114cfb8e25051 to your computer and use it in GitHub Desktop.
silverstripe - add dataobject button to cms / modeladmin
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
class BillingAgreement extends DataObject | |
{ | |
public function getCMSActions() { | |
$fields = parent::getCMSActions(); | |
$button = new FormAction('doMarkProcessed', 'Mark Processed'); | |
//$button->addExtraClass('ss-ui-action-constructive'); | |
$fields->push($button); | |
return $fields; | |
} | |
// ... | |
} | |
class BillingAgreementAdmin extends ModelAdmin { | |
public static $managed_models = array( | |
'BillingAgreement' => array('title' => 'Billing Agreements'), | |
'BillingAgreementDefaultLineItem' => array('title' => 'Default Line Items'), | |
'BillingAgreementEmailTemplate' => array('title' => 'Email Templates') | |
); | |
public function getEditForm($id = null, $fields = null) { | |
$form = parent::getEditForm($id, $fields); | |
$gridField = $form->Fields()->fieldByName($this->sanitiseClassName($this->modelClass)); | |
$config = new GridFieldConfig_RecordEditor(); | |
if($this->modelClass == 'BillingAgreement') { | |
$config->addComponent($export = new GridFieldExportButton()); | |
$config->getComponentByType('GridFieldDetailForm')->setItemRequestClass('BillingAgreementForm_ItemRequest'); | |
} | |
// ... | |
$gridField->setConfig($config); | |
return $form; | |
} | |
} | |
class BillingAgreementForm_ItemRequest extends GridFieldDetailForm_ItemRequest { | |
private static $allowed_actions = array( | |
'edit', | |
'view', | |
'ItemEditForm' | |
); | |
public function ItemEditForm(){ | |
$form = parent::ItemEditForm(); | |
$actions = $this->record->getCMSActions(); | |
if($actions->exists()) { | |
$form->Actions()->merge($actions); | |
} | |
return $form; | |
} | |
public function doMarkProcessed($data, $form) { | |
$this->record->MarkProcessed(); | |
// ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment