|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dynamic\DynamicBlocks\Block; |
|
4
|
|
|
|
|
5
|
|
|
use Dynamic\DynamicBlocks\Model\PromoObject; |
|
6
|
|
|
use SheaDawson\Blocks\Model\Block; |
|
7
|
|
|
use SilverStripe\Forms\GridField\GridField; |
|
8
|
12 |
|
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor; |
|
9
|
|
|
use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchButton; |
|
10
|
12 |
|
use Symbiote\GridFieldExtensions\GridFieldOrderableRows; |
|
11
|
|
|
|
|
12
|
|
|
class PromoBlock extends Block |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @return string |
|
16
|
1 |
|
*/ |
|
17
|
|
|
public function singular_name() |
|
18
|
1 |
|
{ |
|
19
|
|
|
return _t('PromoBlock.SINGULARNAME', 'Promos Block'); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @return string |
|
24
|
|
|
*/ |
|
25
|
|
|
public function plural_name() |
|
26
|
|
|
{ |
|
27
|
|
|
return _t('PromoBlock.PLURALNAME', 'Promos Blocks'); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var array |
|
32
|
|
|
*/ |
|
33
|
|
|
private static $many_many = array( |
|
34
|
|
|
'Promos' => PromoObject::class, |
|
35
|
|
|
); |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var array |
|
39
|
|
|
*/ |
|
40
|
1 |
|
private static $many_many_extraFields = array( |
|
41
|
|
|
'Promos' => array( |
|
42
|
1 |
|
'SortOrder' => 'Int', |
|
43
|
|
|
), |
|
44
|
1 |
|
); |
|
45
|
1 |
|
|
|
46
|
1 |
|
/** |
|
47
|
|
|
* @return FieldList |
|
48
|
1 |
|
*/ |
|
49
|
1 |
|
public function getCMSFields() |
|
50
|
1 |
|
{ |
|
51
|
1 |
|
$fields = parent::getCMSFields(); |
|
52
|
1 |
|
|
|
53
|
1 |
|
$fields->removeByName(array( |
|
54
|
1 |
|
'Promos', |
|
55
|
|
|
)); |
|
56
|
1 |
|
|
|
57
|
1 |
|
if ($this->ID) { |
|
58
|
1 |
|
$config = GridFieldConfig_RelationEditor::create(); |
|
59
|
1 |
|
$config->addComponent(new GridFieldOrderableRows('SortOrder')); |
|
60
|
|
|
$config->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
|
61
|
1 |
|
$config->addComponent(new GridFieldAddExistingSearchButton()); |
|
62
|
|
|
$promos = $this->Promos()->sort('SortOrder'); |
|
|
|
|
|
|
63
|
|
|
$promoField = GridField::create('Promos', 'Promos', $promos, $config); |
|
64
|
|
|
|
|
65
|
|
|
$fields->addFieldsToTab('Root.Promos', array( |
|
66
|
|
|
$promoField, |
|
67
|
1 |
|
)); |
|
68
|
|
|
} |
|
69
|
1 |
|
|
|
70
|
|
|
return $fields; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return mixed |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getPromoList() |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->Promos()->sort('SortOrder'); |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
} |
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: