Skip to content

Commit

Permalink
Added ModelAdmin Example
Browse files Browse the repository at this point in the history
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
UndefinedOffset committed Aug 24, 2013
1 parent 1e963bf commit 53eef90
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions docs/HasManyExample.md
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 1 addition & 0 deletions docs/ManyManyExample.md
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
38 changes: 38 additions & 0 deletions docs/ModelAdminExample.md
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';
}
```

0 comments on commit 53eef90

Please sign in to comment.