PHP code example of twohill / silverstripe-gridfield-newwindowaction
1. Go to this page and download the library: Download twohill/silverstripe-gridfield-newwindowaction library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
twohill / silverstripe-gridfield-newwindowaction example snippets
namespace My\Admin;
use My\Model;
use My\ModelGridFieldFormItemRequest;
use SilverStripe\Admin\ModelAdmin;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldDetailForm;
class MyModelAdmin extends ModelAdmin
{
// Usual ModelAdmin stuff here
private static $managed_models = [Model::class];
public function getEditForm($id = null, $fields = null)
{
$form = parent::getEditForm($id, $fields);
/** @var GridField $gridField */
$gridField = $form->Fields()->first();
$config = $gridField->getConfig();
/** @var GridFieldDetailForm $myForm */
$myForm = $config->getComponentByType(GridFieldDetailForm::class);
$myForm->setItemRequestClass(ModelGridFieldFormItemRequest::class);
return $form;
}
}
namespace My\Admin;
use My\Model;
use Twohill\Forms\NewWindowAction;
use SilverStripe\Versioned\VersionedGridFieldItemRequest;
class ModelGridFieldFormItemRequest extends VersionedGridFieldItemRequest
{
private static $allowed_actions = [
'edit',
'view',
'ItemEditForm',
'generatePDFInvoice',
];
protected function getFormActions()
{
$actions = parent::getFormActions();
$actions->push(NewWindowAction::create('generatePDFInvoice', 'Generate PDF Invoice')
->setUseButtonTag(true)
->addExtraClass('btn-primary font-icon-block-content'));
return $actions;
}
public function generatePDFInvoice() {
/** @var Model $invoice */
$invoice = $this->getRecord();
//$invoice->generatePDFInvoice();
}
}