1 | <?php |
||
3 | class PromoBlock extends Block |
||
4 | { |
||
5 | /** |
||
6 | * @return string |
||
7 | */ |
||
8 | 12 | public function singular_name() |
|
12 | |||
13 | /** |
||
14 | * @return string |
||
15 | */ |
||
16 | 1 | public function plural_name() |
|
17 | { |
||
18 | 1 | return _t('PromoBlock.PLURALNAME', 'Promos 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 | $fields->removeByName(array( |
|
45 | 1 | 'Promos', |
|
46 | 1 | )); |
|
47 | |||
48 | 1 | if ($this->ID) { |
|
49 | 1 | $config = GridFieldConfig_RelationEditor::create(); |
|
50 | 1 | $config->addComponent(new GridFieldOrderableRows('SortOrder')); |
|
51 | 1 | $config->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
|
52 | 1 | $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
53 | 1 | $promos = $this->Promos()->sort('SortOrder'); |
|
|
|||
54 | 1 | $promoField = GridField::create('Promos', 'Promos', $promos, $config); |
|
55 | |||
56 | 1 | $fields->addFieldsToTab('Root.Promos', 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() |
|
71 | } |
If you implement
__call
and 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
__call
is implemented by a parent class and only the child class knows which methods exist: