1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class FormBlock extends Block |
4
|
|
|
{ |
5
|
|
|
/** |
6
|
|
|
* @var string |
7
|
|
|
*/ |
8
|
|
|
private static $singular_name = 'Form Block'; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @var string |
12
|
|
|
*/ |
13
|
|
|
private static $plural_name = 'Form Blocks'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var array |
17
|
|
|
*/ |
18
|
|
|
private static $db = array( |
19
|
|
|
'Content' => 'HTMLText', |
20
|
|
|
); |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
private static $has_one = array( |
26
|
|
|
'Form' => 'UserDefinedForm', |
27
|
|
|
); |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return FieldList |
31
|
|
|
*/ |
32
|
1 |
|
public function getCMSFields() |
33
|
|
|
{ |
34
|
1 |
|
$fields = singleton('Block')->getCMSFields(); |
35
|
|
|
|
36
|
|
|
if (class_exists('UserDefinedForm')) { |
37
|
|
|
$fields->addFieldToTab('Root.Main', DropdownField::create( |
38
|
|
|
'FormID', |
39
|
|
|
'Form', |
40
|
|
|
UserDefinedForm::get()->map() |
41
|
|
|
)->setEmptyString('') |
42
|
|
|
->setDescription('select an existing User Defined Form to display') |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$fields->addFieldToTab('Root.Main', HtmlEditorField::create('Content')); |
47
|
|
|
|
48
|
|
|
return $fields; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return Forms|HTMLText |
53
|
|
|
*/ |
54
|
|
|
public function BlockForm() |
55
|
|
|
{ |
56
|
|
|
if ($this->Form()->exists()) { |
|
|
|
|
57
|
|
|
$controller = new UserDefinedForm_Controller($this->Form()); |
|
|
|
|
58
|
|
|
$current = Controller::curr(); |
59
|
|
|
if ($current && $current->getAction() == 'finished') { |
60
|
|
|
return $controller->renderWith('ReceivedFormSubmission'); |
61
|
|
|
} |
62
|
|
|
$form = $controller->Form(); |
63
|
|
|
return $form; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param null $member |
69
|
|
|
* @return bool |
70
|
|
|
*/ |
71
|
|
|
public function canCreate($member = null) |
72
|
|
|
{ |
73
|
|
|
if (!class_exists('UserDefinedForm')) { |
74
|
|
|
return false; |
75
|
|
|
} |
76
|
|
|
return parent::canCreate(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param null $member |
81
|
|
|
* @return bool |
82
|
|
|
*/ |
83
|
|
|
public function canView($member = null) |
84
|
|
|
{ |
85
|
|
|
if (!class_exists('UserDefinedForm')) { |
86
|
|
|
return false; |
87
|
|
|
} |
88
|
|
|
return parent::canView(); |
89
|
|
|
} |
90
|
|
|
} |
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: