-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated examples to say they are written with 3.0.x in mind and public statics should be private in 3.1.x
- Loading branch information
1 parent
1e963bf
commit 53eef90
Showing
4 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
ModelAdmin implementation Example | ||
================= | ||
Please note this example is written with 3.0.x in mind, if you are using 3.1.x make sure you scope all static properties to private not public. | ||
```php | ||
/**** MyModelAdmin.php ****/ | ||
class MyModelAdmin extends ModelAdmin { | ||
public static $menu_title='My Model Admin'; | ||
public static $url_segment='my-model-admin'; | ||
|
||
public 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 { | ||
public static $db=array( | ||
'Title'=>'Varchar', | ||
'SortOrder'=>'Int' | ||
); | ||
|
||
public static $default_sort='SortOrder'; | ||
} | ||
``` |