Completed
Push — master ( 27e2c5...e639df )
by Nicolaas
03:34
created

StoreAdmin::getEditForm()   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 12
nc 5
nop 2
dl 0
loc 19
rs 8.2222
c 0
b 0
f 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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
13
{
14
    /**
15
     * standard SS variable.
16
     *
17
     * @var string
18
     */
19
    private static $url_segment = 'shop';
0 ignored issues
show
Unused Code introduced by
The property $url_segment is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
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
Unused Code introduced by
The property $menu_title is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
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
Unused Code introduced by
The property $menu_priority is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
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
Unused Code introduced by
The property $menu_icon is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
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)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
74
    {
75
        $form = parent::getEditForm($id, $fields);
76
        if (is_subclass_of($this->modelClass, 'EcommerceDBConfig') || $this->modelClass === 'EcommerceDBConfig') {
77
            $record = EcommerceDBConfig::get()->first();
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
94
}
95