mirror of
https://github.com/UndefinedOffset/SortableGridField.git
synced 2024-10-22 17:05:38 +02:00
39 lines
1.2 KiB
Markdown
39 lines
1.2 KiB
Markdown
ModelAdmin implementation Example
|
|
=================
|
|
|
|
```php
|
|
/**** MyModelAdmin.php ****/
|
|
class MyModelAdmin extends ModelAdmin {
|
|
private static $menu_title = 'My Model Admin';
|
|
|
|
private static $url_segment = 'my-model-admin';
|
|
|
|
private static $managed_models = array(
|
|
'MATestObject',
|
|
);
|
|
|
|
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' && $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'));
|
|
}
|
|
}
|
|
|
|
return $form;
|
|
}
|
|
}
|
|
|
|
/**** MATestObject.php ****/
|
|
class MATestObject extends DataObject {
|
|
private static $db = array(
|
|
'Title' => 'Varchar',
|
|
'SortOrder' => 'Int',
|
|
);
|
|
|
|
private static $default_sort = 'SortOrder';
|
|
}
|
|
``` |