mirror of
https://github.com/UndefinedOffset/SortableGridField.git
synced 2024-10-22 17:05:38 +02:00
Merge pull request #134 from GuySartorelli/enh/injectable
NEW Extend new AbstractGridFieldComponent class
This commit is contained in:
commit
f5a5346349
@ -12,7 +12,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"silverstripe/framework": "~4.0",
|
||||
"silverstripe/framework": "~4.11",
|
||||
"silverstripe/versioned": "^1.0",
|
||||
"silverstripe/vendor-plugin": "^1.0"
|
||||
},
|
||||
|
@ -17,16 +17,16 @@ class TestPage extends Page
|
||||
public function getCMSFields()
|
||||
{
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
|
||||
$conf = GridFieldConfig_RelationEditor::create(10);
|
||||
$conf->addComponent(new GridFieldSortableRows('SortOrder'));
|
||||
$conf->addComponent(GridFieldSortableRows::create('SortOrder'));
|
||||
|
||||
$fields->addFieldToTab(
|
||||
'Root.TestObjects',
|
||||
'Root.TestObjects',
|
||||
GridField::create(
|
||||
'TestObjects',
|
||||
'TestObjects',
|
||||
$this->TestObjects(),
|
||||
'TestObjects',
|
||||
'TestObjects',
|
||||
$this->TestObjects(),
|
||||
$conf
|
||||
)
|
||||
);
|
||||
|
@ -25,9 +25,9 @@ class TestPage extends Page
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
$conf = GridFieldConfig_RelationEditor::create(10);
|
||||
$conf->addComponent(new GridFieldSortableRows('SortOrder'));
|
||||
$conf->addComponent(GridFieldSortableRows::create('SortOrder'));
|
||||
|
||||
$fields->addFieldToTab('Root.TestObjects', new GridField('TestObjects', 'TestObjects', $this->TestObjects(), $conf));
|
||||
$fields->addFieldToTab('Root.TestObjects', GridField::create('TestObjects', 'TestObjects', $this->TestObjects(), $conf));
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
@ -10,24 +10,24 @@ use UndefinedOffset\SortableGridField\Forms\GridFieldSortableRows;
|
||||
class MyModelAdmin extends ModelAdmin
|
||||
{
|
||||
private static $menu_title = 'My Model Admin';
|
||||
|
||||
|
||||
private static $url_segment = 'my-model-admin';
|
||||
|
||||
|
||||
private static $managed_models = [
|
||||
MATestObject::class,
|
||||
];
|
||||
|
||||
|
||||
public function getEditForm($id = null, $fields = null)
|
||||
{
|
||||
$form = parent::getEditForm($id, $fields);
|
||||
|
||||
|
||||
// This check is simply to ensure you are on the managed model you want adjust accordingly
|
||||
if ($this->modelClass === MATestObject::class) {
|
||||
$gridField = $form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass));
|
||||
|
||||
|
||||
// This is just a precaution to ensure we got a GridField from dataFieldByName() which you should have
|
||||
if ($gridField instanceof GridField) {
|
||||
$gridField->getConfig()->addComponent(new GridFieldSortableRows('SortOrder'));
|
||||
$gridField->getConfig()->addComponent(GridFieldSortableRows::create('SortOrder'));
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ class MATestObject extends DataObject
|
||||
'Title' => 'Varchar',
|
||||
'SortOrder' => 'Int',
|
||||
];
|
||||
|
||||
|
||||
private static $indexes = [
|
||||
'SortOrder' => true,
|
||||
];
|
||||
|
@ -6,6 +6,7 @@ use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Core\ClassInfo;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Forms\GridField\AbstractGridFieldComponent;
|
||||
use SilverStripe\Forms\GridField\GridField;
|
||||
use SilverStripe\Forms\GridField\GridField_ActionProvider;
|
||||
use SilverStripe\Forms\GridField\GridField_DataManipulator;
|
||||
@ -30,7 +31,7 @@ use SilverStripe\View\Requirements;
|
||||
/**
|
||||
* This component provides a checkbox which when checked enables drag-and-drop re-ordering of elements displayed in a {@link GridField}
|
||||
*/
|
||||
class GridFieldSortableRows implements GridField_HTMLProvider, GridField_ActionProvider, GridField_DataManipulator
|
||||
class GridFieldSortableRows extends AbstractGridFieldComponent implements GridField_HTMLProvider, GridField_ActionProvider, GridField_DataManipulator
|
||||
{
|
||||
/** @var string */
|
||||
protected $sortColumn;
|
||||
|
Loading…
Reference in New Issue
Block a user