-
Notifications
You must be signed in to change notification settings - Fork 2
/
profile2.admin.inc
96 lines (85 loc) · 2.59 KB
/
profile2.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
<?php
// $Id$
/**
* @file
* Profile type editing UI.
*/
/**
* UI controller.
*/
class Profile2TypeUIController extends EntityDefaultUIController {
/**
* Overrides hook_menu() defaults.
*/
public function hook_menu() {
$items = parent::hook_menu();
$items[$this->path]['description'] = 'Manage profiles, including fields.';
return $items;
}
}
/**
* Generates the profile type editing form.
*/
function profile2_type_form($form, &$form_state, $profile_type, $op = 'edit') {
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->isLocked() && $op != 'clone',
'#machine_name' => array(
'exists' => 'profile2_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['data']['#tree'] = TRUE;
$form['data']['registration'] = array(
'#type' => 'checkbox',
'#title' => t('Show during user account registration.'),
'#default_value' => !empty($profile_type->data['registration']),
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save profile type'),
'#weight' => 40,
);
if (!$profile_type->isLocked() && $op != 'add') {
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete profile type'),
'#weight' => 45,
'#limit_validation_errors' => array(),
'#submit' => array('profile2_type_form_submit_delete')
);
}
return $form;
}
/**
* Form API submit callback for the type form.
*/
function profile2_type_form_submit(&$form, &$form_state) {
$profile_type = entity_ui_form_submit_build_entity($form, $form_state);
// Save and go back.
$profile_type->save();
$form_state['redirect'] = 'admin/structure/profiles';
}
/**
* Form API submit callback for the delete button.
*/
function profile2_type_form_submit_delete(&$form, &$form_state) {
$form_state['redirect'] = 'admin/structure/profiles/manage/' . $form_state['profile2_type']->type . '/delete';
}