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
|
|
|
return array(); |
17
|
|
|
} |
18
|
|
|
$models = EcommerceConfig::get($this->class, 'managed_models'); |
19
|
|
|
foreach ($models as $key => $model) { |
|
|
|
|
20
|
|
|
if (is_array($model)) { |
21
|
|
|
$model = $key; |
22
|
|
|
} |
23
|
|
|
if (!class_exists($model)) { |
24
|
|
|
unset($models[$key]); |
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
Config::inst()->update('ModelAdminEcommerceBaseClass', 'managed_models', $models); |
28
|
|
|
|
29
|
|
|
return parent::getManagedModels(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Change this variable if you don't want the Import from CSV form to appear. |
34
|
|
|
* This variable can be a boolean or an array. |
35
|
|
|
* If array, you can list className you want the form to appear on. i.e. array('myClassOne','myClasstwo'). |
36
|
|
|
*/ |
37
|
|
|
public $showImportForm = false; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* |
41
|
|
|
* @param DataObject $record |
42
|
|
|
* |
43
|
|
|
* @return Form |
|
|
|
|
44
|
|
|
*/ |
45
|
|
|
function oneItemForm($record) |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
Config::inst()->update('LeftAndMain', 'tree_class', $record->ClassName); |
48
|
|
|
$form = LeftAndMain::getEditForm($record); |
|
|
|
|
49
|
|
|
$idField = HiddenField::create('ID')->setValue($record->ID); |
50
|
|
|
$cssField = LiteralField::create( |
51
|
|
|
'oneItemFormCSS', |
52
|
|
|
' |
53
|
|
|
<style> |
54
|
|
|
.cms-content-view .ui-tabs-nav { |
55
|
|
|
margin-left: 0!important; |
56
|
|
|
} |
57
|
|
|
.cms-content-view .Actions { |
58
|
|
|
position: fixed; |
59
|
|
|
bottom: 16px; |
60
|
|
|
right: 16px; |
61
|
|
|
} |
62
|
|
|
</style> |
63
|
|
|
' |
64
|
|
|
); |
65
|
|
|
$form->Fields()->push($idField); |
|
|
|
|
66
|
|
|
$form->Fields()->push($cssField); |
67
|
|
|
return $form; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Define which fields are used in the {@link getEditForm} GridField export. |
72
|
|
|
* By default, it uses the summary fields from the model definition. |
73
|
|
|
* |
74
|
|
|
* @return array |
75
|
|
|
*/ |
76
|
|
|
public function getExportFields() { |
77
|
|
|
$obj = singleton($this->modelClass); |
78
|
|
|
if($obj->hasMethod('getExportFields')) { |
79
|
|
|
return $obj->getExportFields(); |
80
|
|
|
} |
81
|
|
|
return $obj->summaryFields(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
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.