Passed
Push — master ( affe64...6c9189 )
by Jason
02:51
created

LocationAdmin::getEditForm()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Dynamic\Locator;
4
5
use SilverStripe\Admin\ModelAdmin;
6
use SilverStripe\Dev\CsvBulkLoader;
7
use SilverStripe\Forms\Form;
8
9
/**
10
 * Class LocationAdmin
11
 */
12
class LocationAdmin extends ModelAdmin
13
{
14
15
    /**
16
     * @var array
17
     */
18
    private static $managed_models = array(
0 ignored issues
show
introduced by
The private property $managed_models is not used, and could be removed.
Loading history...
19
        Location::class,
20
        LocationCategory::class,
21
    );
22
23
    /**
24
     * @var array
25
     */
26
    private static $model_importers = array(
0 ignored issues
show
introduced by
The private property $model_importers is not used, and could be removed.
Loading history...
27
        Location::class => LocationCsvBulkLoader::class,
28
        LocationCategory::class => CsvBulkLoader::class,
29
    );
30
31
    /**
32
     * @var string
33
     */
34
    private static $menu_title = 'Locator';
0 ignored issues
show
introduced by
The private property $menu_title is not used, and could be removed.
Loading history...
35
    /**
36
     * @var string
37
     */
38
    private static $url_segment = 'locator';
0 ignored issues
show
introduced by
The private property $url_segment is not used, and could be removed.
Loading history...
39
40
    /**
41
     * @return array
42
     */
43
    public function getExportFields()
44
    {
45
        if ($this->modelClass == 'Location') {
46
            return array(
47
                'Title' => 'Name',
48
                'Address' => 'Address',
49
                'City' => 'City',
50
                'State' => 'State',
51
                'PostalCode' => 'PostalCode',
52
                'Country' => 'Country',
53
                'Website' => 'Website',
54
                'Phone' => 'Phone',
55
                'Fax' => 'Fax',
56
                'Email' => 'Email',
57
                'ShowInLocator' => 'ShowInLocator',
58
                'Featured' => 'Featured',
59
                'Lat' => 'Lat',
60
                'Lng' => 'Lng',
61
            );
62
        }
63
64
        return parent::getExportFields();
65
    }
66
67
    /**
68
     * @param null $id
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $id is correct as it would always require null to be passed?
Loading history...
69
     * @param null $fields
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $fields is correct as it would always require null to be passed?
Loading history...
70
     * @return $this|Form
71
     */
72
    public function getEditForm($id = null, $fields = null)
73
    {
74
        $form = parent::getEditForm($id, $fields);
75
        $class = $this->sanitiseClassName($this->modelClass);
76
        if ($class == 'Location') {
77
            $gridField = $form->Fields()->fieldByName($class);
78
            $config = $gridField->getConfig();
79
            $config->removeComponentsByType('GridFieldDeleteAction');
80
        }
81
        return $form;
82
    }
83
}
84