function computing_command_form in Drupal Computing 7.2
This is similar to system_settings_form(). Make all data in 'input', and add "Add" button and other generic fields.
1 string reference to 'computing_command_form'
- computing_add_command in ./
computing.admin.inc - Generate a form for a command. We expect this function will create a computing record.
File
- ./
computing.admin.inc, line 146
Code
function computing_command_form($form, &$form_state, $command_data) {
// 1. process $form data. make them into $form['input']
if (isset($command_data['form elements callback']) && function_exists($command_data['form elements callback'])) {
$form['input'] = array(
'#type' => 'fieldset',
'#title' => t('Configure input parameters for %command', array(
'%command' => $command_data['title'],
)),
//'#weight' => 5,
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#tree' => TRUE,
);
$form['input'] = $form['input'] + call_user_func($command_data['form elements callback']);
}
else {
$form['no_input'] = array(
'#type' => 'fieldset',
'#title' => t('Configure parameters for %command', array(
'%command' => $command_data['title'],
)),
//'#weight' => 5,
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#description' => t('This command has no input parameter.'),
);
}
// 2. add other command data.
$form['common'] = array(
'#type' => 'fieldset',
'#title' => t('Configure generic parameters'),
//'#weight' => 5,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
);
$form['common']['application'] = array(
'#type' => 'textfield',
'#title' => 'Application',
'#title_display' => 'before',
'#default_value' => $command_data['application'],
'#disabled' => TRUE,
);
$form['common']['command'] = array(
'#type' => 'textfield',
'#title' => 'Command',
'#title_display' => 'before',
'#default_value' => $command_data['command'],
'#disabled' => TRUE,
);
$form['common']['label'] = array(
'#type' => 'textfield',
'#title' => 'Label',
'#description' => 'The human-readable name of this command.',
'#default_value' => $command_data['title'],
'#required' => TRUE,
);
$form['common']['weight'] = array(
'#type' => 'textfield',
'#title' => 'Weight',
'#description' => 'Command execution weight. Low number has higher priority.',
'#default_value' => 0,
'#element_validation' => 'element_validate_integer',
'#required' => TRUE,
);
$form['common']['status'] = array(
'#type' => 'select',
'#title' => 'Status',
'#options' => computing_status_readable(),
//'#description' => 'Command execution weight. Low number has higher priority.',
'#default_value' => 'RDY',
'#disabled' => TRUE,
);
// 3. add code from system_settings_form().
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Add Command'),
);
if (!empty($_POST) && form_get_errors()) {
drupal_set_message(t('The command cannot be added because of the errors.'), 'error');
}
$form['#submit'][] = 'computing_command_form_submit';
return $form;
}