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
![]() |
|||
24 | LocationPage::class, |
||
25 | LocationCategory::class, |
||
26 | ]; |
||
27 | |||
28 | /** |
||
29 | * @var array |
||
30 | */ |
||
31 | private static $model_importers = [ |
||
0 ignored issues
–
show
|
|||
32 | LocationCategory::class => CsvBulkLoader::class, |
||
33 | ]; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | private static $menu_title = 'Locations'; |
||
0 ignored issues
–
show
|
|||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | private static $url_segment = 'locations'; |
||
0 ignored issues
–
show
|
|||
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
|
|||
82 | * @param null $fields |
||
0 ignored issues
–
show
|
|||
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 |