Completed
Push — master ( 5a8cc3...81a72c )
by
unknown
12s
created

ElementForm::getType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
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 ElementForm()
0 ignored issues
show
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
29
    {
30
        $controller = new UserDefinedFormController($this);
31
        $current = Controller::curr();
32
33
        if ($current && $current->getAction() == 'finished') {
34
            return $controller->renderWith(UserDefinedFormController::class .'_ReceivedFormSubmission');
35
        }
36
37
        $form = $controller->Form();
38
        $form->setFormAction(
39
            Controller::join_links(
40
                $current->Link(),
41
                'element',
42
                $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...
43
                'Form'
44
            )
45
        );
46
47
        return $form;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $form returns the type SilverStripe\Forms\Form which is incompatible with the documented return type SilverStripe\UserForms\UserForm.
Loading history...
48
    }
49
50
    public function Link($action = null)
51
    {
52
        $current = Controller::curr();
53
54
        if ($action === 'finished') {
55
            return Controller::join_links(
56
                $current->Link(),
57
                'finished'
58
            );
59
        }
60
61
        return parent::Link($action);
62
    }
63
64
    public function getType()
65
    {
66
        return _t(__CLASS__ . '.BlockType', 'Form');
67
    }
68
}
69