-
Notifications
You must be signed in to change notification settings - Fork 7
/
profile.admin.inc
225 lines (196 loc) · 6.76 KB
/
profile.admin.inc
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
/**
* @file
* Profile type editing UI.
*/
/**
* Generates the profile type editing form.
*/
function profile_display_settings_form($form, &$form_state) {
$form['#config'] = 'profile.settings';
$profile_display = config_get('profile.settings', 'profile_display');
$form['profile_display'] = array(
'#title' => t('Profile edit display'),
'#type' => 'radios',
'#options' => array(
'tabs' => t('Tabs'),
'fieldsets' => t('Fieldsets'),
),
'#default_value' => $profile_display,
'#description' => t('Display profile edit forms as separate tabs under the account edit tab, or as fieldsets on the account edit page.'),
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
'#weight' => 40,
);
return $form;
}
/**
* Generates the profile type editing form.
*/
function profile_display_settings_form_submit($form, &$form_state) {
config_set('profile.settings', 'profile_display', $form_state['values']['profile_display']);
backdrop_set_message(t('The configuration settings have been saved.'));
menu_rebuild();
}
/**
* Generates the profile type editing form.
*/
function profile_type_form($form, &$form_state, $profile_type, $op = 'edit') {
if (!isset($profile_type) && $op == 'add') {
$profile_type = profile_type_set_defaults();
}
backdrop_set_title(t('Add profile type'));
$form['#profile_type'] = $profile_type;
$form['profile_type'] = array(
'#value' => $profile_type,
'#type' => 'value',
);
if ($op == 'clone') {
$profile_type->label .= ' (cloned)';
$profile_type->type = '';
}
$form['label'] = array(
'#title' => t('Label'),
'#type' => 'textfield',
'#default_value' => $profile_type->label,
'#description' => t('The human-readable name of this profile type.'),
'#required' => TRUE,
'#size' => 30,
);
// Machine-readable type name.
$form['type'] = array(
'#type' => 'machine_name',
'#default_value' => isset($profile_type->type) ? $profile_type->type : '',
'#maxlength' => 32,
'#disabled' => ($profile_type->storage == PROFILE_STORAGE_DEFAULT) && $op != 'clone',
'#machine_name' => array(
'exists' => 'profile_get_types',
'source' => array('label'),
),
'#description' => t('A unique machine-readable name for this profile type. It must only contain lowercase letters, numbers, and underscores.'),
);
$form['registration'] = array(
'#type' => 'checkbox',
'#title' => t('Show during user account registration.'),
'#default_value' => !empty($profile_type->registration),
);
$user_roles = user_roles();
// Exclude anonymous user role.
unset($user_roles[BACKDROP_ANONYMOUS_ROLE]);
$form['roles'] = array(
'#type' => 'checkboxes',
'#title' => t('Roles'),
'#description' => t('Check user roles that should have this profile.'),
'#options' => $user_roles,
'#default_value' => !empty($profile_type->roles) ? $profile_type->roles : array_keys($user_roles)
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save profile type'),
'#weight' => 40,
);
$form['weight'] = array(
'#type' => 'weight',
'#title' => t('Weight'),
'#default_value' => $profile_type->weight,
'#description' => t('When showing profiles, those with lighter (smaller) weights get listed before profiles with heavier (larger) weights.'),
'#weight' => 10,
);
if ($profile_type->storage === PROFILE_STORAGE_NORMAL && $op != 'add' && $op != 'clone') {
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete profile type'),
'#weight' => 45,
'#limit_validation_errors' => array(),
'#submit' => array('profile_type_form_submit_delete')
);
}
return $form;
}
/**
* Form API submit callback for the type form.
*/
function profile_type_form_submit(&$form, &$form_state) {
$form_state['values']['roles'] = array_filter($form_state['values']['roles']);
$profile_type = $form_state['values']['profile_type'];
$profile_type->label = $form_state['values']['label'];
$profile_type->type = $form_state['values']['type'];
$profile_type->roles = $form_state['values']['roles'];
$profile_type->weight = $form_state['values']['weight'];
$profile_type->registration = $form_state['values']['registration'];
profile_type_save($profile_type);
// Clear menu cache so profile edit tabs adopt new weights.
menu_rebuild();
$form_state['redirect'] = 'admin/structure/profiles';
}
/**
* Form API submit callback for the delete button.
*/
function profile_type_form_submit_delete(&$form, &$form_state) {
$form_state['redirect'] = 'admin/structure/profiles/manage/' . $form['#profile_type']->type . '/delete';
}
/**
* Form API submit callback for the delete button.
*/
function profile_type_delete_form($form, &$form_state, $profile_type) {
$form_state['profile_type'] = $profile_type;
$confirm_question = t('Are you sure you want to delete the %label profile type?', array('%label' => $profile_type->label));
return confirm_form($form, $confirm_question, 'admin/structure/profiles');
}
/**
* Form API submit callback for the delete button.
*/
function profile_type_delete_form_submit($form, &$form_state) {
profile_type_delete($form_state['profile_type']);
backdrop_set_message(t('The profile type %name has been deleted.', array('%name' => $form_state['profile_type']->type)));
$form_state['redirect'] = 'admin/structure/profiles/manage';
return;
}
/**
* Builds the entity overview form.
*/
function profile_type_overview_form($form, &$form_state) {
$entities = profile_get_types();
$rows = array();
foreach ($entities as $entity) {
$rows[] = profile_type_overview_form_row($entity->type, $entity);
}
$render = array(
'#theme' => 'table',
'#header' => array(t('Label'), t('Status'), array('data' => t('Operations'), 'colspan' => 4)),
'#rows' => $rows,
'#empty' => t('None.'),
);
$form['table'] = $render;
$form['pager'] = array('#theme' => 'pager');
return $form;
}
/**
* Generates the row for the passed entity and may be overridden in order to
* customize the rows.
*/
function profile_type_overview_form_row($id, $entity) {
$entity_uri = 'admin/structure/profiles';
$row[] = $entity->label;
// Add a row for the exportable status.
if ($entity->storage === PROFILE_STORAGE_OVERRIDE) {
$storage = t('Overridden');
}
elseif ($entity->storage === PROFILE_STORAGE_DEFAULT) {
$storage = t('Default (module-provided)');
}
else {
$storage = t('Custom');
}
$row[] = $storage;
$operations = array(
'#type' => 'dropbutton',
'#links' => _profile_get_operations($id, $entity),
);
$row[] = backdrop_render($operations);
return $row;
}