function workflow_node_form in Workflow 6
Same name and namespace in other branches
- 5.2 workflow.module \workflow_node_form()
- 5 workflow.module \workflow_node_form()
- 6.2 workflow.module \workflow_node_form()
- 7 workflow.module \workflow_node_form()
Form builder. Add form widgets for workflow change to $form.
This builder is factored out of workflow_form_alter() because it is also used on the Workflow tab.
Parameters
$form: An existing form definition array.
$name: The name of the workflow.
$current: The state ID of the current state, used as the default value.
$choices: An array of possible target states.
2 calls to workflow_node_form()
- workflow_form_alter in ./
workflow.module - Implementation of hook_form_alter().
- workflow_tab_form in ./
workflow.pages.inc - Form builder. Allow workflow state change and scheduling from workflow tab.
File
- ./
workflow.module, line 237 - Support workflows made up of arbitrary states.
Code
function workflow_node_form(&$form, $form_state, $title, $name, $current, $choices, $timestamp = NULL, $comment = NULL) {
// No sense displaying choices if there is only one choice.
if (sizeof($choices) == 1) {
$form['workflow'][$name] = array(
'#type' => 'hidden',
'#value' => $current,
);
}
else {
$form['workflow'][$name] = array(
'#type' => 'radios',
'#title' => $form['#wf']->options['name_as_title'] ? $title : '',
'#options' => $choices,
'#name' => $name,
'#parents' => array(
'workflow',
),
'#default_value' => $current,
);
// Display scheduling form only if a node is being edited and user has
// permission. State change cannot be scheduled at node creation because
// that leaves the node in the (creation) state.
if (!(arg(0) == 'node' && arg(1) == 'add') && user_access('schedule workflow transitions')) {
$scheduled = $timestamp ? 1 : 0;
$timestamp = $scheduled ? $timestamp : time();
$form['workflow']['workflow_scheduled'] = array(
'#type' => 'radios',
'#title' => t('Schedule'),
'#options' => array(
t('Immediately'),
t('Schedule for state change at:'),
),
'#default_value' => isset($form_state['values']['workflow_scheduled']) ? $form_state['values']['workflow_scheduled'] : $scheduled,
);
$form['workflow']['workflow_scheduled_date'] = array(
'#type' => 'date',
'#default_value' => array(
'day' => isset($form_state['values']['workflow_scheduled_date']['day']) ? $form_state['values']['workflow_scheduled_date']['day'] : format_date($timestamp, 'custom', 'j'),
'month' => isset($form_state['values']['workflow_scheduled_date']['month']) ? $form_state['values']['workflow_scheduled_date']['month'] : format_date($timestamp, 'custom', 'n'),
'year' => isset($form_state['values']['workflow_scheduled_date']['year']) ? $form_state['values']['workflow_scheduled_date']['year'] : format_date($timestamp, 'custom', 'Y'),
),
);
$hours = format_date($timestamp, 'custom', 'H:i');
$form['workflow']['workflow_scheduled_hour'] = array(
'#type' => 'textfield',
'#description' => t('Please enter a time in 24 hour (eg. HH:MM) format. If no time is included, the default will be midnight on the specified date. The current time is: ') . format_date(time()),
'#default_value' => $scheduled ? isset($form_state['values']['workflow_scheduled_hour']) ? $form_state['values']['workflow_scheduled_hour'] : $hours : NULL,
);
}
if (isset($form['#tab'])) {
$determiner = 'comment_log_tab';
}
else {
$determiner = 'comment_log_node';
}
$form['workflow']['workflow_comment'] = array(
'#type' => $form['#wf']->options[$determiner] ? 'textarea' : 'hidden',
'#title' => t('Comment'),
'#description' => t('A comment to put in the workflow log.'),
'#default_value' => $comment,
'#rows' => 2,
);
}
}