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

PasswordForm::getFields()   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
48
    /**
49
     * @return FieldList
50
     */
51
    protected function getFields()
52
    {
53
        return FieldList::create([
54
            PasswordField::create('Password', _t(__CLASS__ . '.PasswordField', 'Password'))
55
        ]);
56
    }
57
58
    /**
59
     * @return FieldList
60
     */
61
    protected function getActions()
62
    {
63
        return FieldList::create([
64
            FormAction::create('doValidate', _t(__CLASS__ . '.Validate', 'Submit'))
65
        ]);
66
    }
67
68
    public function getFormValidator()
69
    {
70
        return RequiredFields::create(['Password']);
71
    }
72
}
73