1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @see: http://doc.silverstripe.org/framework/en/reference/ModelAdmin |
5
|
|
|
* |
6
|
|
|
* @author Nicolaas [at] sunnyside up . co .nz |
7
|
|
|
*/ |
8
|
|
|
class ModelAdminEcommerceBaseClass extends ModelAdmin |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @return array Map of class name to an array of 'title' (see {@link $managed_models}) |
|
|
|
|
12
|
|
|
*/ |
13
|
|
|
public function getManagedModels() |
14
|
|
|
{ |
15
|
|
|
if($this->class === 'ModelAdminEcommerceBaseClass') { |
16
|
|
|
//never used |
17
|
|
|
return array('Order' => array('title' => 'All Orders')); |
18
|
|
|
} |
19
|
|
|
return parent::getManagedModels(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Change this variable if you don't want the Import from CSV form to appear. |
24
|
|
|
* This variable can be a boolean or an array. |
25
|
|
|
* If array, you can list className you want the form to appear on. i.e. array('myClassOne','myClasstwo'). |
26
|
|
|
*/ |
27
|
|
|
public $showImportForm = false; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* |
31
|
|
|
* @param DataObject $record |
32
|
|
|
* |
33
|
|
|
* @return Form |
|
|
|
|
34
|
|
|
*/ |
35
|
|
|
function oneItemForm($record) |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
Config::inst()->update('LeftAndMain', 'tree_class', $record->ClassName); |
38
|
|
|
$form = LeftAndMain::getEditForm($record); |
|
|
|
|
39
|
|
|
$idField = HiddenField::create('ID')->setValue($record->ID); |
40
|
|
|
$cssField = LiteralField::create( |
41
|
|
|
'oneItemFormCSS', |
42
|
|
|
' |
43
|
|
|
<style> |
44
|
|
|
.cms-content-view .ui-tabs-nav { |
45
|
|
|
margin-left: 0!important; |
46
|
|
|
} |
47
|
|
|
.cms-content-view .Actions { |
48
|
|
|
position: fixed; |
49
|
|
|
bottom: 16px; |
50
|
|
|
right: 16px; |
51
|
|
|
} |
52
|
|
|
</style> |
53
|
|
|
' |
54
|
|
|
); |
55
|
|
|
$form->Fields()->push($idField); |
|
|
|
|
56
|
|
|
$form->Fields()->push($cssField); |
57
|
|
|
return $form; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Define which fields are used in the {@link getEditForm} GridField export. |
62
|
|
|
* By default, it uses the summary fields from the model definition. |
63
|
|
|
* |
64
|
|
|
* @return array |
65
|
|
|
*/ |
66
|
|
|
public function getExportFields() { |
67
|
|
|
$obj = singleton($this->modelClass); |
68
|
|
|
if($obj->hasMethod('getExportFields')) { |
69
|
|
|
return $obj->getExportFields(); |
70
|
|
|
} |
71
|
|
|
return $obj->summaryFields(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.