ElementForm   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
c 1
b 0
f 0
dl 0
loc 59
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getType() 0 3 1
A Link() 0 12 2
A Form() 0 21 3
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;
0 ignored issues
show
introduced by
The trait SilverStripe\UserForms\UserForm requires some properties which are not provided by DNADesign\ElementalUserForms\Model\ElementForm: $Name, $SubmitButtonText, $OnCompleteMessage, $ShowInSummary, $ShowClearButton, $ClearButtonText
Loading history...
14
15
    private static $table_name = 'ElementForm';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
16
17
    private static $icon = 'font-icon-block-form';
0 ignored issues
show
introduced by
The private property $icon is not used, and could be removed.
Loading history...
18
19
    private static $controller_class = ElementFormController::class;
0 ignored issues
show
introduced by
The private property $controller_class is not used, and could be removed.
Loading history...
20
21
    private static $singular_name = 'form';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
22
23
    private static $plural_name = 'forms';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
24
25
    private static $inline_editable = false;
0 ignored issues
show
introduced by
The private property $inline_editable is not used, and could be removed.
Loading history...
26
27
    /**
28
     * @return UserForm
29
     */
30
    public function Form()
31
    {
32
        $controller = UserDefinedFormController::create($this);
33
        $current = Controller::curr();
34
        $controller->setRequest($current->getRequest());
35
36
        if ($current && $current->getAction() == 'finished') {
37
            return $controller->renderWith(UserDefinedFormController::class .'_ReceivedFormSubmission');
38
        }
39
40
        $form = $controller->Form();
41
        $form->setFormAction(
42
            Controller::join_links(
43
                $current->Link(),
44
                'element',
45
                $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...
46
                'Form'
47
            )
48
        );
49
50
        return $form;
51
    }
52
53
    public function Link($action = null)
54
    {
55
        $current = Controller::curr();
56
57
        if ($action === 'finished') {
58
            return Controller::join_links(
59
                $current->Link(),
60
                'finished'
61
            );
62
        }
63
64
        return parent::Link($action);
65
    }
66
67
    public function getType()
68
    {
69
        return _t(__CLASS__ . '.BlockType', 'Form');
70
    }
71
}
72