|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DNADesign\ElementalUserForms\Control; |
|
4
|
|
|
|
|
5
|
|
|
use DNADesign\Elemental\Controllers\ElementController; |
|
6
|
|
|
use SilverStripe\Control\Controller; |
|
7
|
|
|
use SilverStripe\UserForms\Control\UserDefinedFormController; |
|
8
|
|
|
use SilverStripe\Control\Director; |
|
9
|
|
|
use SilverStripe\Core\Injector\Injector; |
|
10
|
|
|
|
|
11
|
|
|
class ElementFormController extends ElementController |
|
12
|
|
|
{ |
|
13
|
|
|
private static $allowed_actions = [ |
|
|
|
|
|
|
14
|
|
|
'Form', |
|
15
|
|
|
'process', |
|
16
|
|
|
'finished' |
|
17
|
|
|
]; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @return SilverStripe\Forms\Form |
|
|
|
|
|
|
21
|
|
|
*/ |
|
22
|
|
|
public function Form() |
|
23
|
|
|
{ |
|
24
|
|
|
$request = $this->getRequest(); |
|
25
|
|
|
|
|
26
|
|
|
$user = UserDefinedFormController::create($this->element); |
|
27
|
|
|
$user->setRequest($request); |
|
28
|
|
|
|
|
29
|
|
|
return $user->Form(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function process($data) |
|
33
|
|
|
{ |
|
34
|
|
|
$request = $this->getRequest(); |
|
35
|
|
|
|
|
36
|
|
|
$user = UserDefinedFormController::create($this->element); |
|
37
|
|
|
$user->setRequest($request); |
|
38
|
|
|
|
|
39
|
|
|
return $user->process($data, $user->Form()); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function finished() |
|
43
|
|
|
{ |
|
44
|
|
|
$request = $this->getRequest(); |
|
45
|
|
|
|
|
46
|
|
|
$user = UserDefinedFormController::create($this->element); |
|
47
|
|
|
$user->setRequest($request); |
|
48
|
|
|
$user->finished(); |
|
49
|
|
|
|
|
50
|
|
|
$page = $this->getPage(); |
|
|
|
|
|
|
51
|
|
|
$controller = Injector::inst()->create($page->getControllerName(), $this->element->getPage()); |
|
52
|
|
|
$element = $this->element; |
|
53
|
|
|
|
|
54
|
|
|
return $controller->customise([ |
|
55
|
|
|
'Content' => $element->renderWith($element->getRenderTemplates('_ReceivedFormSubmission')), |
|
56
|
|
|
]); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param string $action |
|
61
|
|
|
* |
|
62
|
|
|
* @return string |
|
63
|
|
|
*/ |
|
64
|
|
|
public function Link($action = null) |
|
65
|
|
|
{ |
|
66
|
|
|
$id = $this->element->ID; |
|
67
|
|
|
$segment = Controller::join_links('element', $id, $action); |
|
68
|
|
|
$page = Director::get_current_page(); |
|
69
|
|
|
|
|
70
|
|
|
if ($page && !($page instanceof ElementController)) { |
|
71
|
|
|
return $page->Link($segment); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
if ($controller = $this->getParentController()) { |
|
|
|
|
|
|
75
|
|
|
return $controller->Link($segment); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $segment; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.