Merge pull request #130 from samandeggs/patch-1

Update ModelAdminExample.md
This commit is contained in:
Robbie Averill 2020-09-17 00:07:24 -07:00 committed by GitHub
commit 7bdeebb6cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 5 deletions

View File

@ -21,11 +21,12 @@ class MyModelAdmin extends ModelAdmin
{
$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) {
// 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'));
}
}