Completed
Pull Request — master (#12)
by Simon
01:19
created

PasswordForm::getActions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Firesphere\PartialUserforms\Forms;
4
5
use Firesphere\PartialUserforms\Controllers\PartialUserFormVerifyController;
6
use Firesphere\PartialUserforms\Models\PartialFormSubmission;
7
use SilverStripe\Control\HTTPResponse;
8
use SilverStripe\Forms\FieldList;
9
use SilverStripe\Forms\Form;
10
use SilverStripe\Forms\FormAction;
11
use SilverStripe\Forms\PasswordField;
12
use SilverStripe\Forms\RequiredFields;
13
use SilverStripe\Forms\Validator;
14
15
class PasswordForm extends Form
16
{
17
    public const PASSWORD_SESSION_KEY = 'PartialFormSession';
18
19
    /**
20
     * PasswordForm constructor.
21
     * @param PartialUserFormVerifyController|null $controller
22
     * @param string $name
23
     * @param FieldList|null $fields
24
     * @param FieldList|null $actions
25
     * @param Validator|null $validator
26
     */
27
    public function __construct(
28
        PartialUserFormVerifyController $controller = null,
29
        $name = self::DEFAULT_NAME,
30
        FieldList $fields = null,
31
        FieldList $actions = null,
32
        Validator $validator = null
33
    ) {
34
        if (!$fields) {
35
            $fields = $this->getFields();
36
        }
37
        if (!$actions) {
38
            $actions = $this->getActions();
39
        }
40
        if (!$validator) {
41
            $validator = $this->getFormValidator();
42
        }
43
        parent::__construct($controller, $name, $fields, $actions, $validator);
44
45
        $this->setFormAction(sprintf('/verify/%s', $name));
46
47
        // Add the userform class to the form, so it's can be styled similar to the actual userforms more easily
48
        $this->addExtraClass('userform');
49
    }
50
51
    /**
52
     * @return FieldList
53
     */
54
    protected function getFields()
55
    {
56
        return FieldList::create([
57
            PasswordField::create('Password', _t(__CLASS__ . '.PasswordField', 'Password'))
58
        ]);
59
    }
60
61
    /**
62
     * @return FieldList
63
     */
64
    protected function getActions()
65
    {
66
        return FieldList::create([
67
            FormAction::create('doValidate', _t(__CLASS__ . '.Validate', 'Submit'))
68
        ]);
69
    }
70
71
    /**
72
     * @return RequiredFields
73
     */
74
    public function getFormValidator()
75
    {
76
        return RequiredFields::create(['Password']);
77
    }
78
}
79