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