LocationsAdmin   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 36
dl 0
loc 81
rs 10
c 1
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getEditForm() 0 13 3
A getExportFields() 0 30 3
1
<?php
2
3
namespace Dynamic\Locator\Admin;
4
5
use Dynamic\Locator\Bulkloader\LocationCsvBulkLoader;
6
use Dynamic\Locator\Model\LocationCategory;
7
use Dynamic\Locator\Page\LocationPage;
8
use LittleGiant\CatalogManager\ModelAdmin\CatalogPageAdmin;
9
use SilverStripe\Dev\CsvBulkLoader;
10
use SilverStripe\Forms\Form;
11
use SilverStripe\Forms\GridField\GridField;
12
13
/**
14
 * Class LocationAdmin
15
 * @package Dynamic\Locator\Admin
16
 */
17
class LocationsAdmin extends CatalogPageAdmin
18
{
19
20
    /**
21
     * @var array
22
     */
23
    private static $managed_models = [
0 ignored issues
show
introduced by
The private property $managed_models is not used, and could be removed.
Loading history...
24
        LocationPage::class,
25
        LocationCategory::class,
26
    ];
27
28
    /**
29
     * @var array
30
     */
31
    private static $model_importers = [
0 ignored issues
show
introduced by
The private property $model_importers is not used, and could be removed.
Loading history...
32
        LocationCategory::class => CsvBulkLoader::class,
33
    ];
34
35
    /**
36
     * @var string
37
     */
38
    private static $menu_title = 'Locations';
0 ignored issues
show
introduced by
The private property $menu_title is not used, and could be removed.
Loading history...
39
40
    /**
41
     * @var string
42
     */
43
    private static $url_segment = 'locations';
0 ignored issues
show
introduced by
The private property $url_segment is not used, and could be removed.
Loading history...
44
45
    /**
46
     * @return array
47
     */
48
    public function getExportFields()
49
    {
50
        if ($this->modelClass == LocationPage::class) {
51
            $fields = [
52
                'Title' => 'Name',
53
                'Address' => 'Address',
54
                'Address2' => 'Address2',
55
                'City' => 'City',
56
                'State' => 'State',
57
                'PostalCode' => 'PostalCode',
58
                'CountryCode' => 'Country',
59
                'Phone' => 'Phone',
60
                'Fax' => 'Fax',
61
                'Email' => 'Email',
62
                'Website' => 'Website',
63
                'Featured' => 'Featured',
64
                'CategoryList' => 'Categories',
65
                'Lat' => 'Lat',
66
                'Lng' => 'Lng',
67
                'Import_ID' => 'Import_ID',
68
            ];
69
        }
70
71
        if (!isset($fields)) {
72
            $fields = parent::getExportFields();
73
        }
74
75
        $this->extend('updateGetExportFields', $fields);
76
77
        return $fields;
78
    }
79
80
    /**
81
     * @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...
82
     * @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...
83
     * @return $this|Form
84
     */
85
    public function getEditForm($id = null, $fields = null)
86
    {
87
        $form = parent::getEditForm($id, $fields);
88
89
        if ($this->modelClass == LocationPage::class) {
90
            /** @var GridField $gridField */
91
            if ($gridField = $form->Fields()->fieldByName($this->sanitiseClassName($this->modelClass))) {
92
                $gridField->getConfig()
93
                    ->removeComponentsByType('GridFieldDeleteAction');
94
            }
95
        }
96
97
        return $form;
98
    }
99
}
100