Added ModelAdmin Example

Updated examples to say they are written with 3.0.x in mind and public statics should be private in 3.1.x
This commit is contained in:
Ed 2013-08-23 21:19:35 -03:00
parent 1e963bfef1
commit 53eef90c97
4 changed files with 41 additions and 0 deletions

View File

@ -35,6 +35,7 @@ To move an item to another page drag the row over the respective page button and
#### Full code Examples
* [has_many relationship] (https://github.com/UndefinedOffset/SortableGridField/blob/master/docs/HasManyExample.md)
* [many_many relationship] (https://github.com/UndefinedOffset/SortableGridField/blob/master/docs/ManyManyExample.md)
* [ModelAdmin implementation] (https://github.com/UndefinedOffset/SortableGridField/blob/master/docs/ModelAdminExample.md)
#### Events
GridFieldSortableRows provides 4 "events" onBeforeGridFieldRowSort(), onAfterGridFieldRowSort(), onBeforeGridFieldPageSort() and onAfterGridFieldPageSort(). These "events" are passed a clone of the DataList used in GridFieldSortableRows, in the case of page sorting this list has a limit that shows you the current page plus/minus one object. For GridFieldSortableRows that are on ModelAdmin decendents these events are called on the ModelAdmin if they do not have a owner DataObject, if you are using GridFieldSortableRows on a GridField for a DataObject's relationship the events are called on that DataObject.

View File

@ -1,5 +1,6 @@
has_many 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
/*** TestPage.php ***/
class TestPage extends Page {

View File

@ -1,5 +1,6 @@
many_many 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
/*** TestPage.php ***/
class TestPage extends Page {

38
docs/ModelAdminExample.md Normal file
View File

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