Completed
Pull Request — 2.0 (#157)
by Jason
11:13
created

LocationAdmin::getEditForm()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 2
1
<?php
2
3
/**
4
 * Class LocationAdmin
5
 */
6
class LocationAdmin extends ModelAdmin
7
{
8
9
    /**
10
     * @var array
11
     */
12
    private static $managed_models = array(
13
        'Location',
14
        'LocationCategory',
15
    );
16
17
    /**
18
     * @var array
19
     */
20
    private static $model_importers = array(
0 ignored issues
show
Unused Code introduced by
The property $model_importers 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...
21
        'Location' => 'LocationCsvBulkLoader',
22
        'LocationCategory' => 'CsvBulkLoader',
23
    );
24
25
    /**
26
     * @var string
27
     */
28
    private static $menu_title = 'Locator';
29
    /**
30
     * @var string
31
     */
32
    private static $url_segment = 'locator';
33
34
    /**
35
     * @return array
36
     */
37
    public function getExportFields()
38
    {
39
        if ($this->modelClass == 'Location') {
40
            return array(
41
                'Title' => 'Name',
42
                'Address' => 'Address',
43
                'Suburb' => 'City',
44
                'State' => 'State',
45
                'Postcode' => 'Postcode',
46
                'Country' => 'Country',
47
                'Website' => 'Website',
48
                'Phone' => 'Phone',
49
                'Fax' => 'Fax',
50
                'Email' => 'Email',
51
                'Category.Name' => 'Category',
52
                'ShowInLocator' => 'ShowInLocator',
53
                'Featured' => 'Featured',
54
                'Lat' => 'Lat',
55
                'Lng' => 'Lng',
56
            );
57
        }
58
59
        return parent::getExportFields();
60
    }
61
62
    /**
63
     * @param null $id
64
     * @param null $fields
65
     * @return $this|Form
66
     */
67
    public function getEditForm($id = null, $fields = null)
68
    {
69
        $form = parent::getEditForm($id, $fields);
70
        $class = $this->sanitiseClassName($this->modelClass);
71
        if ($class == 'Location') {
72
            $gridField = $form->Fields()->fieldByName($class);
73
            $config = $gridField->getConfig();
74
            $config->removeComponentsByType('GridFieldDeleteAction');
75
        }
76
        return $form;
77
    }
78
}
79