|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class PromoBlock extends Block |
|
4
|
|
|
{ |
|
5
|
|
|
/** |
|
6
|
|
|
* @return string |
|
7
|
|
|
*/ |
|
8
|
6 |
|
public function singular_name() |
|
9
|
|
|
{ |
|
10
|
6 |
|
return _t('PromoBlock.SINGULARNAME', 'Promo Block'); |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @return string |
|
15
|
|
|
*/ |
|
16
|
|
|
public function plural_name() |
|
17
|
|
|
{ |
|
18
|
|
|
return _t('PromoBlock.PLURALNAME', 'Promo Blocks'); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var array |
|
23
|
|
|
*/ |
|
24
|
|
|
private static $many_many = array( |
|
25
|
|
|
'Promos' => 'PromoObject', |
|
26
|
|
|
); |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var array |
|
30
|
|
|
*/ |
|
31
|
|
|
private static $many_many_extraFields = array( |
|
32
|
|
|
'Promos' => array( |
|
33
|
|
|
'SortOrder' => 'Int', |
|
34
|
|
|
), |
|
35
|
|
|
); |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @return FieldList |
|
39
|
|
|
*/ |
|
40
|
1 |
|
public function getCMSFields() |
|
41
|
|
|
{ |
|
42
|
1 |
|
$fields = parent::getCMSFields(); |
|
43
|
|
|
|
|
44
|
1 |
|
if ($this->ID) { |
|
45
|
1 |
|
$config = GridFieldConfig_RelationEditor::create(); |
|
46
|
1 |
|
if (class_exists('GridFieldSortableRows')) { |
|
47
|
|
|
$config->addComponent(new GridFieldSortableRows('SortOrder')); |
|
48
|
|
|
} |
|
49
|
1 |
|
if (class_exists('GridFieldAddExistingSearchButton')) { |
|
50
|
1 |
|
$config->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
|
51
|
1 |
|
$config->addComponent(new GridFieldAddExistingSearchButton()); |
|
52
|
1 |
|
} |
|
53
|
1 |
|
$promos = $this->Promos()->sort('SortOrder'); |
|
|
|
|
|
|
54
|
1 |
|
$promoField = GridField::create('Promos', 'Promos', $promos, $config); |
|
55
|
|
|
|
|
56
|
1 |
|
$fields->addFieldsToTab('Root.Main', array( |
|
57
|
1 |
|
$promoField, |
|
58
|
1 |
|
)); |
|
59
|
1 |
|
} |
|
60
|
|
|
|
|
61
|
1 |
|
return $fields; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return mixed |
|
66
|
|
|
*/ |
|
67
|
1 |
|
public function getPromoList() |
|
68
|
|
|
{ |
|
69
|
1 |
|
return $this->Promos()->sort('SortOrder'); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param null $member |
|
74
|
|
|
* @return bool|null |
|
75
|
|
|
*/ |
|
76
|
1 |
|
public function canCreate($member = null) |
|
77
|
|
|
{ |
|
78
|
|
|
if (!$member || !(is_a($member, 'Member')) || is_numeric($member)) { |
|
79
|
|
|
$member = Member::currentUserID(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
// Standard mechanism for accepting permission changes from extensions |
|
83
|
|
|
$extended = $this->extendedCan('canCreate', $member); |
|
84
|
|
|
if ($extended !== null) { |
|
85
|
1 |
|
return $extended; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
return parent::canCreate($member); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @param null $member |
|
93
|
|
|
* @return bool|null |
|
94
|
|
|
*/ |
|
95
|
|
|
public function canView($member = null) |
|
96
|
|
|
{ |
|
97
|
|
|
if (!$member || !(is_a($member, 'Member')) || is_numeric($member)) { |
|
98
|
|
|
$member = Member::currentUserID(); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
// Standard mechanism for accepting permission changes from extensions |
|
102
|
|
|
$extended = $this->extendedCan('canView', $member); |
|
103
|
|
|
if ($extended !== null) { |
|
104
|
|
|
return $extended; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
return parent::canView($member); |
|
108
|
|
|
} |
|
109
|
|
|
} |
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: