NEW Extend new AbstractGridFieldComponent class

This makes the `GridFieldSortableRows` component `Injectable`, and
allows any future enhancements in the new abstract class to
automatically apply without requiring additional changes in this module.

The class is introduced in silverstripe/framework 4.11.0 so the
dependency constraint needs to be updated.
This commit is contained in:
Guy Sartorelli 2022-02-12 19:19:13 +13:00
parent fff3f08901
commit e374c93ae3
5 changed files with 18 additions and 17 deletions

View File

@ -12,7 +12,7 @@
}
],
"require": {
"silverstripe/framework": "~4.0",
"silverstripe/framework": "~4.11",
"silverstripe/versioned": "^1.0",
"silverstripe/vendor-plugin": "^1.0"
},

View File

@ -19,7 +19,7 @@ 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',

View File

@ -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;
}

View File

@ -27,7 +27,7 @@ class MyModelAdmin extends ModelAdmin
// 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'));
}
}

View File

@ -8,6 +8,7 @@ use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Extensible;
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;
@ -36,7 +37,7 @@ use SilverStripe\View\Requirements;
*
* @package forms
*/
class GridFieldSortableRows implements GridField_HTMLProvider, GridField_ActionProvider, GridField_DataManipulator
class GridFieldSortableRows extends AbstractGridFieldComponent implements GridField_HTMLProvider, GridField_ActionProvider, GridField_DataManipulator
{
/** @var string */
protected $sortColumn;