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 |
View Code Duplication |
public function getCMSFields() |
|
|
|
|
33
|
|
|
{ |
34
|
1 |
|
$fields = singleton('Block')->getCMSFields(); |
35
|
|
|
|
36
|
1 |
|
if (class_exists('UserDefinedForm')) { |
37
|
|
|
$fields->addFieldToTab('Root.Main', DropdownField::create( |
38
|
|
|
'FormID', |
39
|
|
|
'Form', |
40
|
|
|
UserDefinedForm::get()->map() |
41
|
|
|
)->setEmptyString('')); |
42
|
|
|
} |
43
|
|
|
|
44
|
1 |
|
$fields->addFieldToTab('Root.Main', HtmlEditorField::create('Content')); |
45
|
|
|
|
46
|
1 |
|
return $fields; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return Forms|HTMLText |
51
|
|
|
*/ |
52
|
|
|
public function BlockForm() |
53
|
|
|
{ |
54
|
|
|
if ($this->Form()->exists()) { |
|
|
|
|
55
|
|
|
$controller = new UserDefinedForm_Controller($this->Form()); |
|
|
|
|
56
|
|
|
$current = Controller::curr(); |
57
|
|
|
if ($current && $current->getAction() == 'finished') { |
58
|
|
|
return $controller->renderWith('ReceivedFormSubmission'); |
59
|
|
|
} |
60
|
|
|
$form = $controller->Form(); |
61
|
|
|
return $form; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param null $member |
67
|
|
|
* @return bool |
68
|
|
|
*/ |
69
|
|
View Code Duplication |
public function canCreate($member = null) |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
if (!class_exists('UserDefinedForm')) { |
72
|
|
|
return false; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
// Standard mechanism for accepting permission changes from extensions |
76
|
|
|
$extended = $this->extendedCan('canCreate', $member); |
77
|
|
|
if ($extended !== null) { |
78
|
|
|
return $extended; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return parent::canCreate(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param null $member |
86
|
|
|
* @return bool |
87
|
|
|
*/ |
88
|
|
View Code Duplication |
public function canView($member = null) |
|
|
|
|
89
|
|
|
{ |
90
|
|
|
if (!class_exists('UserDefinedForm')) { |
91
|
|
|
return false; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
// Standard mechanism for accepting permission changes from extensions |
95
|
|
|
$extended = $this->extendedCan('canView', $member); |
96
|
|
|
if ($extended !== null) { |
97
|
|
|
return $extended; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return parent::canView(); |
101
|
|
|
} |
102
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.