Passed
Pull Request — master (#173)
by Matthew
13:34
created

LocationAdmin::getExportFields()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

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