<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
level51 / silverstripe-data-object-actions example snippets
namespace My\Awesome\Project;
use Level51\DataObjectActions\DataObjectActionProvider;
use Level51\DataObjectActions\DataObjectAction;
use SilverStripe\Forms\FieldList;
use SilverStripe\ORM\DataObject;
// Implement DataObjectActionProvider interface on your DataObject
class MyDataObject extends DataObject implements DataObjectActionProvider {
// Return a field list containing all custom actions, each one of type DataObjectAction or DataObjectLink
public function getCustomActions()
{
return FieldList::create(
[
DataObjectAction::create('myCustomAction', 'My Custom Action')
->addExtraClass('btn-outline-primary font-icon-rocket')
->setUseButtonTag(true),
DataObjectLink::create('externalLink', 'External Link', 'https://lvl51.de')
->addExtraClass('btn-outline-dark font-icon-external-link')
->setNewWindow(true)
]
);
}
// Implement the handler method(s)
public function myCustomAction($data, $form)
{
// Do stuff, e.g. set a property
// Do NOT call $this->write(), this will be done automatically
// throw a new \SilverStripe\ORM\ValidationResult in case something failed
// Optionally return a success message
return 'Success message';
}
}
public function updateCustomActions(FieldList $fields)
{
$fields->push(
DataObjectAction::create(...)
);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.