Passed
Push — master ( e1bc3e...2c9d90 )
by Robbie
02:54 queued 01:10
created

ElementFormController::finished()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
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 = [
0 ignored issues
show
Unused Code introduced by
The property $allowed_actions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
14
        'Form',
15
        'process',
16
        'finished'
17
    ];
18
19
    /**
20
     * @return SilverStripe\Forms\Form
0 ignored issues
show
Bug introduced by
The type DNADesign\ElementalUserF...SilverStripe\Forms\Form was not found. Did you mean SilverStripe\Forms\Form? If so, make sure to prefix the type with \.
Loading history...
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();
0 ignored issues
show
Bug introduced by
The method getPage() does not exist on DNADesign\ElementalUserF...l\ElementFormController. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
        /** @scrutinizer ignore-call */ 
51
        $page = $this->getPage();
Loading history...
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()) {
0 ignored issues
show
Bug introduced by
The method getParentController() does not exist on DNADesign\ElementalUserF...l\ElementFormController. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

74
        if ($controller = $this->/** @scrutinizer ignore-call */ getParentController()) {
Loading history...
75
            return $controller->Link($segment);
76
        }
77
78
        return $segment;
79
    }
80
}
81