This repository was archived by the owner on Oct 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApiUserForm.php
More file actions
executable file
·125 lines (113 loc) · 3.37 KB
/
ApiUserForm.php
File metadata and controls
executable file
·125 lines (113 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* Api User Config form object
*
* PHP Version 5.3
*
* @category Forms
* @package AW
* @author Alex Wyett <alex@wyett.co.uk>
* @copyright 2013 Alex Wyett
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @link http://www.github.com/alexwyett
*/
/**
* Api User Config form object. Extends the generic form and provides a static helper
* method to build the form object
*
* PHP Version 5.3
*
* @category Forms
* @package AW
* @author Alex Wyett <alex@wyett.co.uk>
* @copyright 2013 Alex Wyett
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @link http://www.github.com/alexwyett
*/
class ApiUserForm extends \aw\formfields\forms\StaticForm
{
/**
* Constructor
*
* @param array $attributes Form attributes
* @param array $formValues Form Values
* @param array $brands Brands
*
* @return void
*/
public static function factory(
$attributes = array(),
$formValues = array(),
$brands = array()
) {
// New form object
$form = new \aw\formfields\forms\Form($attributes, $formValues);
// Fieldset
$fs = \aw\formfields\fields\Fieldset::factory(
'Create an Api User',
array(
'class' => 'user-details'
)
);
// Add key field
$fs->addChild(
self::getNewLabelAndTextField(
'User Name'
)->getElementBy('getType', 'text')
->setName('key')
->setId('key')
->setAttribute('placeholder', 'Alpha/Numeric characters only')
->setRule('ValidSlug', true)
->getParent()
);
// Add email field
$fs->addChild(
self::getNewLabelAndTextField(
'Email Address'
)->getElementBy('getType', 'text')
->setName('email')
->setId('email')
->setRule('ValidEmail', true)
->getParent()
);
// Add secret field
$fs->addChild(
self::getNewLabelAndTextField(
'Secret (optional)'
)->getElementBy('getType', 'text')
->setName('secret')
->setId('secret')
->getParent()
);
// Add fieldset to form
$form->addChild($fs);
// Add submit button
$form->addChild(
new \aw\formfields\fields\SubmitButton(
array(
'value' => 'Create User',
'id' => 'formsubmit'
)
)
);
// Add brand checkboxes for additional roleouts
if (count($brands) > 0) {
// Fieldset
$fs = \aw\formfields\fields\Fieldset::factory(
'Add to additional brands?',
array(
'class' => 'additional-brands'
)
);
foreach ($brands as $brandCode => $brandName) {
$fs->addChild(
self::getNewLabelAndCheckboxField(
$brandCode
)->setLabel($brandName)
);
}
$form->addChild($fs);
}
return $form->mapValues();
}
}