Completed
Push — master ( 81a72c...02e7ff )
by
unknown
12s
created

ElementForm::ElementForm()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 12
nc 2
nop 0
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace DNADesign\ElementalUserForms\Model;
4
5
use SilverStripe\UserForms\Control\UserDefinedFormController;
6
use SilverStripe\UserForms\UserForm;
7
use SilverStripe\Control\Controller;
8
use DNADesign\Elemental\Models\BaseElement;
9
use DNADesign\ElementalUserForms\Control\ElementFormController;
10
11
class ElementForm extends BaseElement
12
{
13
    use UserForm;
14
15
    private static $table_name = 'ElementForm';
0 ignored issues
show
Unused Code introduced by
The property $table_name 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...
16
17
    private static $icon = 'dnadesign/silverstripe-elemental-userforms:images/form.svg';
0 ignored issues
show
Unused Code introduced by
The property $icon 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...
18
19
    private static $controller_class = ElementFormController::class;
0 ignored issues
show
Unused Code introduced by
The property $controller_class 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...
20
21
    private static $singular_name = 'form';
0 ignored issues
show
Unused Code introduced by
The property $singular_name 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...
22
23
    private static $plural_name = 'forms';
0 ignored issues
show
Unused Code introduced by
The property $plural_name 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...
24
25
    /**
26
     * @return UserForm
27
     */
28
    public function Form()
29
    {
30
        $controller = UserDefinedFormController::create($this);
31
        $current = Controller::curr();
32
        $controller->setRequest($current->getRequest());
33
34
        if ($current && $current->getAction() == 'finished') {
35
            return $controller->renderWith(UserDefinedFormController::class .'_ReceivedFormSubmission');
36
        }
37
38
        $form = $controller->Form();
39
        $form->setFormAction(
40
            Controller::join_links(
41
                $current->Link(),
42
                'element',
43
                $this->owner->ID,
0 ignored issues
show
Bug Best Practice introduced by
The property owner does not exist on DNADesign\ElementalUserForms\Model\ElementForm. Since you implemented __get, consider adding a @property annotation.
Loading history...
44
                'Form'
45
            )
46
        );
47
48
        return $form;
49
    }
50
51
    public function Link($action = null)
52
    {
53
        $current = Controller::curr();
54
55
        if ($action === 'finished') {
56
            return Controller::join_links(
57
                $current->Link(),
58
                'finished'
59
            );
60
        }
61
62
        return parent::Link($action);
63
    }
64
65
    public function getType()
66
    {
67
        return _t(__CLASS__ . '.BlockType', 'Form');
68
    }
69
}
70