function csm_form in Custom Submit Messages 7
Page callback: CSM settings
See also
csm_menu()
1 string reference to 'csm_form'
- csm_menu in ./
csm.module - Implements hook_menu().
File
- ./
csm.module, line 328 - The main module file for Custom Submit Messages.
Code
function csm_form($form, &$form_state) {
// Load user_roles() (we'll need this names of each role for the form labels)
// and load the saved settings for the form.
$user_roles = user_roles();
$form_defaults = variable_get('csm_attributes', NULL);
// Re-index the $form_defaults by weight and then re-sort. Then, when we build
// the form we can step through the array in weight order, and the form entries
// will be displayed in weight order. If $form_defaults is not set yet (i.e.,
// if the form has not been saved yet) then just index by rid.
if ($form_defaults !== NULL) {
foreach ($form_defaults as $rid => $defaults) {
$form_defaults_sorted_by_weight[$defaults['weight']] = array(
'rid' => $rid,
'checkbox' => $defaults['checkbox'],
);
}
ksort($form_defaults_sorted_by_weight);
}
else {
foreach ($user_roles as $rid => $role) {
$form_defaults_sorted_by_weight[$rid] = array(
'rid' => $rid,
'checkbox' => 0,
);
}
}
// Build the form
$form['csm_attributes'] = array(
'#prefix' => '<div id="curve-attributes">',
'#suffix' => '</div>',
'#tree' => TRUE,
'#theme' => 'csm_components',
);
foreach ($form_defaults_sorted_by_weight as $weight => $values) {
$form['csm_attributes'][$values['rid']]['label'] = array(
'#type' => 'item',
'#markup' => $user_roles[$values['rid']],
);
$form['csm_attributes'][$values['rid']]['checkbox'] = array(
'#type' => 'checkbox',
'#default_value' => $values['checkbox'],
);
$form['csm_attributes'][$values['rid']]['weight'] = array(
'#type' => 'textfield',
'#default_value' => $weight,
'#size' => 3,
'#attributes' => array(
'class' => array(
'item-row-weight',
),
),
);
}
return system_settings_form($form);
}