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( |
|
|
|
|
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 |
|
|
|
|
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
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.