StoreAdmin::getManagedModels()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
nc 4
nop 0
1
<?php
2
3
4
/**
5
 * @description: CMS management for the store setup (e.g Order Steps, Countries, etc...)
6
 *
7
 * @authors: Nicolaas [at] Sunny Side Up .co.nz
8
 * @package: ecommerce
9
 * @sub-package: cms
10
 * @inspiration: Silverstripe Ltd, Jeremy
11
 **/
12
class StoreAdmin extends ModelAdminEcommerceBaseClass
13
{
14
    /**
15
     * standard SS variable.
16
     *
17
     * @var string
18
     */
19
    private static $url_segment = 'shop';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
20
21
    /**
22
     * standard SS variable.
23
     *
24
     * @var string
25
     */
26
    private static $menu_title = 'Shop Settings';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
27
28
    /**
29
     * standard SS variable.
30
     *
31
     * @var int
32
     */
33
    private static $menu_priority = 3.3;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
34
35
    /**
36
     * standard SS variable.
37
     *
38
     * @var string
39
     */
40
    private static $menu_icon = 'ecommerce/images/icons/cart-file.gif';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
41
42
    public function init()
43
    {
44
        parent::init();
45
    }
46
47
    /**
48
     *@return string (URLSegment)
49
     **/
50
    public function urlSegmenter()
51
    {
52
        return $this->config()->get('url_segment');
53
    }
54
55
    /**
56
     * @return array Map of class name to an array of 'title' (see {@link $managed_models})
57
     *               we make sure that the EcommerceDBConfig is FIRST
58
     */
59
    public function getManagedModels()
60
    {
61
        $models = parent::getManagedModels();
62
        $ecommerceDBConfig = isset($models['EcommerceDBConfig']) ? $models['EcommerceDBConfig'] : null;
63
        if ($ecommerceDBConfig) {
64
            unset($models['EcommerceDBConfig']);
65
66
            return array('EcommerceDBConfig' => $ecommerceDBConfig) + $models;
67
        }
68
69
        return $models;
70
    }
71
72
73
    public function getEditForm($id = null, $fields = null)
74
    {
75
        $form = parent::getEditForm($id, $fields);
76
        if ($this->modelClass === 'EcommerceDBConfig' || is_subclass_of($this->modelClass, 'EcommerceDBConfig')) {
77
            $record = DataObject::get_one('EcommerceDBConfig');
78
            if ($record && $record->exists()) {
79
                return $this->oneItemForm($record);
80
            }
81
            if ($gridField = $form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass))) {
82
                if ($gridField instanceof GridField) {
83
                    $config = $gridField->getConfig();
84
                    $config->removeComponentsByType('GridFieldExportButton');
85
                    $config->removeComponentsByType('GridFieldPrintButton');
86
                }
87
            }
88
        }
89
90
        return $form;
91
    }
92
}
93