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( |
|
|
|
|
19
|
|
|
Location::class, |
20
|
|
|
LocationCategory::class, |
21
|
|
|
); |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
private static $model_importers = array( |
|
|
|
|
27
|
|
|
Location::class => LocationCsvBulkLoader::class, |
28
|
|
|
LocationCategory::class => CsvBulkLoader::class, |
29
|
|
|
); |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private static $menu_title = 'Locator'; |
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private static $url_segment = 'locator'; |
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
|
|
public function getExportFields() |
44
|
|
|
{ |
45
|
|
|
if ($this->modelClass == Location::class) { |
46
|
|
|
$fields = [ |
47
|
|
|
'Title' => 'Name', |
48
|
|
|
'Address' => 'Address', |
49
|
|
|
'Address2' => 'Address2', |
50
|
|
|
'City' => 'City', |
51
|
|
|
'State' => 'State', |
52
|
|
|
'PostalCode' => 'PostalCode', |
53
|
|
|
'CountryCode' => 'Country', |
54
|
|
|
'Phone' => 'Phone', |
55
|
|
|
'Fax' => 'Fax', |
56
|
|
|
'Email' => 'Email', |
57
|
|
|
'Website' => 'Website', |
58
|
|
|
'Featured' => 'Featured', |
59
|
|
|
'CategoryList' => 'Categories', |
60
|
|
|
'Lat' => 'Lat', |
61
|
|
|
'Lng' => 'Lng', |
62
|
|
|
'Import_ID' => 'Import_ID', |
63
|
|
|
]; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if (!isset($fields)) { |
67
|
|
|
$fields = parent::getExportFields(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$this->extend('updateGetExportFields', $fields); |
71
|
|
|
|
72
|
|
|
return $fields; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param null $id |
|
|
|
|
77
|
|
|
* @param null $fields |
|
|
|
|
78
|
|
|
* @return $this|Form |
79
|
|
|
*/ |
80
|
|
|
public function getEditForm($id = null, $fields = null) |
81
|
|
|
{ |
82
|
|
|
$form = parent::getEditForm($id, $fields); |
83
|
|
|
$class = $this->sanitiseClassName($this->modelClass); |
84
|
|
|
if ($class == Location::class) { |
85
|
|
|
$gridField = $form->Fields()->fieldByName($class); |
|
|
|
|
86
|
|
|
$config = $gridField->getConfig(); |
87
|
|
|
$config->removeComponentsByType('GridFieldDeleteAction'); |
88
|
|
|
} |
89
|
|
|
return $form; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|