1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverCommerce\ContactAdmin\Admin; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Dev\CsvBulkLoader; |
6
|
|
|
use Colymba\BulkManager\BulkManager; |
7
|
|
|
use SilverStripe\Forms\CheckboxField; |
8
|
|
|
use SilverCommerce\ContactAdmin\Model\Contact; |
9
|
|
|
use SilverCommerce\ContactAdmin\Model\ContactTag; |
10
|
|
|
use SilverCommerce\ContactAdmin\Model\ContactList; |
11
|
|
|
use SilverCommerce\ContactAdmin\BulkActions\AddTagsHandler; |
12
|
|
|
use SilverCommerce\ContactAdmin\BulkActions\AddToListHandler; |
13
|
|
|
use ilateral\SilverStripe\ModelAdminPlus\ModelAdminPlus; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Management interface for contacts |
17
|
|
|
* |
18
|
|
|
* @author ilateral |
19
|
|
|
* @package Contacts |
20
|
|
|
*/ |
21
|
|
|
class ContactAdmin extends ModelAdminPlus |
22
|
|
|
{ |
23
|
|
|
private static $menu_priority = 0; |
|
|
|
|
24
|
|
|
|
25
|
|
|
private static $managed_models = [ |
|
|
|
|
26
|
|
|
Contact::class, |
27
|
|
|
ContactTag::class, |
28
|
|
|
ContactList::class |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
private static $url_segment = 'contacts'; |
|
|
|
|
32
|
|
|
|
33
|
|
|
private static $menu_title = 'Contacts'; |
|
|
|
|
34
|
|
|
|
35
|
|
|
private static $model_importers = [ |
|
|
|
|
36
|
|
|
Contact::class => CSVBulkLoader::class, |
37
|
|
|
ContactTag::class => CSVBulkLoader::class, |
38
|
|
|
ContactList::class => CSVBulkLoader::class |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
private static $allowed_actions = [ |
|
|
|
|
42
|
|
|
"SearchForm" |
43
|
|
|
]; |
44
|
|
|
|
45
|
|
|
public $showImportForm = [ |
46
|
|
|
Contact::class, |
47
|
|
|
ContactTag::class, |
48
|
|
|
ContactList::class |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
private static $menu_icon_class = 'font-icon-torso'; |
|
|
|
|
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Listen for customised export fields on the currently managed object |
58
|
|
|
* |
59
|
|
|
* @return array |
60
|
|
|
*/ |
61
|
|
|
public function getExportFields() |
62
|
|
|
{ |
63
|
|
|
$model = singleton($this->modelClass); |
64
|
|
|
if ($model->hasMethod('getExportFields')) { |
65
|
|
|
return $model->getExportFields(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return parent::getExportFields(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function getEditForm($id = null, $fields = null) |
72
|
|
|
{ |
73
|
|
|
$form = parent::getEditForm($id, $fields); |
74
|
|
|
$class = $this->sanitiseClassName($this->modelClass); |
75
|
|
|
$gridField = $form->Fields()->fieldByName($class); |
76
|
|
|
$config = $gridField->getConfig(); |
77
|
|
|
|
78
|
|
|
// Add bulk editing to gridfield |
79
|
|
|
$manager = $config->getComponentByType(BulkManager::class); |
80
|
|
|
|
81
|
|
|
if ($this->modelClass == Contact::class) { |
82
|
|
|
$manager->addBulkAction(AddTagsHandler::class); |
83
|
|
|
$manager->addBulkAction(AddToListHandler::class); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$this->extend("updateEditForm", $form); |
87
|
|
|
|
88
|
|
|
return $form; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function getList() |
92
|
|
|
{ |
93
|
|
|
// Get contacts via Search Context results |
94
|
|
|
if ($this->modelClass == Contact::class) { |
95
|
|
|
/** @var Contact */ |
96
|
|
|
$context = singleton(Contact::class)->getDefaultSearchContext(); |
97
|
|
|
return $context->getResults([]); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$list = parent::getList(); |
101
|
|
|
|
102
|
|
|
$this->extend('updateContactAdminList', $list); |
103
|
|
|
|
104
|
|
|
return $list; |
105
|
|
|
} |
106
|
|
|
} |