forked from coldfrontlabs/fserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fserver.pages.inc
179 lines (157 loc) · 5.65 KB
/
fserver.pages.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
<?php
/**
* @file
* Page forms
*/
/**
* Form settings for the Project entity
*/
function fserver_project_form(&$form, &$form_state) {
if (isset($form['title'])) {
$form['title']['#weight'] = -10;
}
if (isset($form['field_compatibility'])) {
$form['field_compatibility']['#weight'] = 0;
}
$form['short_name'] = array(
'#type' => 'machine_name',
'#title' => t('Project Short Name'),
'#description' => t('Machine-name of the project for this release.'),
'#size' => 40,
'#maxlength' => 255,
'#machine_name' => array(
'exists' => 'fserver__project_exists',
'source' => array('title'),
'label' => t('Project short name'),
),
'#weight' => -9,
'#default_value' => isset($form['entity']['#value']->short_name) ? $form['entity']['#value']->short_name : '',
);
$form['project_status'] = array(
'#type' => 'select',
'#title' => t('Project Status'),
'#multiple' => FALSE,
'#description' => t('Status code for the project. Affects how updates are displayed by the Update module.'),
'#options' => array(
# @see https://api.drupal.org/api/drupal/modules%21update%21update.compare.inc/7
'published' => t('Published'),
'unpublished' => t('Unpublished'),
'insecure' => t('Insecure'),
'revoked' => t('Revoked'),
'unsupported' => t('Unsupported'),
),
'#default_value' => isset($form['entity']['#value']->project_status) ? $form['entity']['#value']->project_status : '',
);
$form['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced'),
'#description' => t('The following options are normally auto-detected based on your repository data. Please use caution when modifying the following.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['advanced']['supported_majors'] = array(
'#type' => 'textfield',
'#title' => t('Supported Majors'),
'#description' => t('Major versions which are supported.'),
'#size' => 40,
'#maxlength' => 255,
// @todo limit based on available major versions
'#weight' => 20,
'#default_value' => isset($form['entity']['#value']->supported_majors) ? $form['entity']['#value']->supported_majors : '',
// @todo add element validator
);
$form['advanced']['recommended_major'] = array(
'#type' => 'numberfield',
'#title' => t('Recommended Major'),
'#description' => t('Major version which is recommended.'),
'#size' => 40,
'#maxlength' => 255,
'#min' => 1,
// @todo validate the major version exists
'#weight' => 20,
'#default_value' => isset($form['entity']['#value']->recommended_major) ? $form['entity']['#value']->recommended_major : '',
);
$form['advanced']['default_major'] = array(
'#type' => 'textfield',
'#title' => t('Default Major'),
'#description' => t('Default major branch.'),
'#size' => 40,
'#maxlength' => 255,
'#weight' => 20,
'#default_value' => isset($form['entity']['#value']->default_major) ? $form['entity']['#value']->default_major : '',
// @todo add element validator
);
# @todo add access check on form
}
/**
* Form settings for the Release entity
*/
function fserver_release_form(&$form, &$form_state) {
$form['project_short_name'] = array(
'#type' => 'textfield',
'#title' => t('Project Short Name'),
'#description' => t('Machine-name of the project for this release.'),
'#size' => 40,
'#maxlength' => 255,
'#default_value' => isset($form['entity']['#value']->project_short_name) ? $form['entity']['#value']->project_short_name : '',
'#element_validate' => '_fserver_release_validate_project_short_name',
'#required' => TRUE,
);
$form['api'] = array(
'#type' => 'select',
'#title' => t('API'),
'#description' => t('API version (i.e. 7.x)'),
'#default_value' => isset($form['entity']['#value']->api) ? $form['entity']['#value']->api : '7.x',
'#required' => TRUE,
'#multiple' => FALSE,
'#options' => array(
'5.x' => t('5.x'),
'6.x' => t('6.x'),
'7.x' => t('7.x'),
'8.x' => t('8.x'),
),
);
$form['version_major'] = array(
'#type' => 'numberfield',
'#title' => t('Version Major'),
'#size' => 15,
'#min' => 1,
'#maxlength' => 3,
'#default_value' => isset($form['entity']['#value']->version_major) ? $form['entity']['#value']->version_major : '',
'#required' => TRUE,
// @todo add auto-detection based on project repo data
);
$form['version_extra'] = array(
'#type' => 'textfield',
'#title' => t('Version Extra'),
'#description' => t('Ex: dev, alpha1'),
'#size' => 15,
'#maxlength' => 20,
'#default_value' => isset($form['entity']['#value']->version_extra) ? $form['entity']['#value']->version_extra : '',
// @todo add custom validator
// @todo add auto-detection based on project repo data
);
$form['version_patch'] = array(
'#type' => 'textfield',
'#title' => t('Version Patch'),
'#size' => 6,
'#maxlength' => 4,
'#default_value' => isset($form['entity']['#value']->version_patch) ? $form['entity']['#value']->version_patch : '',
// @todo add custom validator
);
# @todo add access check on form
}
/**
* Validate the name of the project
*/
function _fserver_release_validate_project_short_name($element, &$form_state, $form) {
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'project')
->propertyCondition('short_name', $form_state['values']['project_short_name'])
->count();
$result = $query->execute();
if ($result <= 0) {
form_error($element, t('Unknown project short name.'));
}
// @todo check that the given user has the rights to create a release for the given project
}