function workflow_tab_form in Workflow 7
Same name and namespace in other branches
- 5.2 workflow.module \workflow_tab_form()
- 5 workflow.module \workflow_tab_form()
- 6.2 workflow.pages.inc \workflow_tab_form()
- 6 workflow.pages.inc \workflow_tab_form()
Form builder. Allow workflow state change and scheduling from workflow tab. N.B. This function is only used for Node API, not Field API.
Parameters
$node: Node for which workflow information will be displayed.
$workflow: Workflow object to display.
$states: Array of states for the workflow.
$current: Current workflow state of this node.
Return value
Form definition array.
2 string references to 'workflow_tab_form'
- workflow_forms in ./
workflow.node.inc - Implements hook_forms().
- workflow_tab_page in ./
workflow.pages.inc - Menu callback. Display workflow summary of a node.
File
- ./
workflow.pages.inc, line 210 - Provide user interface for changing workflow state.
Code
function workflow_tab_form($form, $form_state, $node, $workflow, $states, $current_sid) {
// Let's make sure we should be here.
if (workflow_tab_access($node) === FALSE) {
return;
}
// @todo: remove this in a future version.
// This is to support workflow-extensions 7.x-1.0, which still passes a $wid.
if (is_numeric($workflow)) {
$workflow = Workflow::load($wid = $workflow);
}
// This function is only used for Node API, not Field API, hence only 'node'.
$state = WorkflowState::load($current_sid);
$options = $state
->getOptions($entity_type = 'node', $node, $force = FALSE);
// Only build form if user has possible target state(s).
if (workflow_show_form($current_sid, $workflow, $options)) {
// Tell FAPI where this form is.
form_load_include($form_state, 'inc', 'workflow', 'workflow.pages');
$form['#tab'] = TRUE;
$name = t($workflow->name);
$form['#wf'] = $workflow;
$form['#choices'] = $options;
$form['#node'] = $node;
// Added for integration with Field widget.
$timestamp = NULL;
$comment = NULL;
// See if scheduling information is present.
if (!empty($node->workflow_scheduled_timestamp) && !empty($node->workflow_scheduled_sid)) {
global $user;
if (variable_get('configurable_timezones', 1) && $user->uid && drupal_strlen($user->timezone)) {
$timezone = $user->timezone;
}
else {
$timezone = variable_get('date_default_timezone', 0);
}
// The default value should be the upcoming sid.
$current_sid = $node->workflow_scheduled_sid;
$timestamp = $node->workflow_scheduled_timestamp;
$comment = $node->workflow_scheduled_comment;
}
// Include the same form elements here that are included on a
// regular node editing page. $form is modified by reference.
workflow_node_form($form, $form_state, t('Change !name state', array(
'!name' => $name,
)), $name, $current_sid, $options, $timestamp, $comment);
$form['node'] = array(
'#type' => 'value',
'#value' => $node,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Update workflow'),
);
}
return $form;
}