function _workflow_extensions_replace_with_buttons in Workflow Extensions 6
Same name and namespace in other branches
- 7 workflow_extensions.module \_workflow_extensions_replace_with_buttons()
1 call to _workflow_extensions_replace_with_buttons()
- workflow_extensions_form_alter in ./
workflow_extensions.module - Implementation of hook_form_alter().
File
- ./
workflow_extensions.module, line 306 - UI-related improvements to the Workflow module and tokens for Rules.
Code
function _workflow_extensions_replace_with_buttons(&$form, $workflow_name) {
$current_sid = $form['workflow'][$workflow_name]['#default_value'];
if (function_exists('workflow_get_state_name')) {
$current_state_name = workflow_get_state_name($current_sid);
}
else {
$current_state = workflow_get_state($current_sid);
$current_state_name = $current_state['state'];
}
// We need a node-context for token replacement. When on the Workflow tab
// form, the node object will already have been loaded on the form.
// When creating content (node/add/<type>) we only have limited data. In
// the remaining cases we load the node from the cache based on the nid
// found on the form.
$form_id = $form['form_id']['#value'];
if (strpos($form_id, 'workflow_tab_form') === 0) {
$node = $form['node']['#value'];
}
elseif (is_numeric($nid = $form['nid']['#value'])) {
$node = node_load($nid);
}
else {
// Creating new content, nid not yet known
$node = $form['#node'];
}
$states = $form['workflow'][$workflow_name]['#options'];
$submit_handlers = _workflow_extensions_assign_handlers($form);
foreach ($states as $sid => $to_state_name) {
if ($sid != $current_sid) {
// Create button for transition from current_sid to destination state.
$button = array();
$button['#value'] = workflow_extensions_get_transition_label($form['#wf']->wid, $current_state_name, workflow_get_state_name($sid), $node);
$button['#type'] = 'submit';
$button['#to_state'] = $sid;
if (isset($form['buttons']['submit']['#weight'])) {
// node form
$button['#weight'] = $form['buttons']['submit']['#weight'] + 1;
}
elseif (isset($form['submit']['#weight'])) {
// comment form
$button['#weight'] = $form['submit']['#weight'];
}
$button['#submit'] = $submit_handlers;
$form['buttons']["submit_to_{$to_state_name}"] = $button;
}
}
// Get rid of workflow radio buttons that live inside the fieldset
unset($form['workflow'][$workflow_name]);
// If after this the fieldset is empty, remove it altogher
if (!isset($form['workflow']['workflow_scheduled']) && (!isset($form['workflow']['workflow_comment']) || $form['workflow']['workflow_comment']['#type'] == 'hidden')) {
unset($form['workflow']);
}
// With the existing Save button now impotent to submit a workflow
// transition, we can re-purpose it for saving all other edits to the
// node without changing the workflow state.
// This does not make sense for the Workflow tab form though, as there is
// nothing to save but a state change. In this case we simply remove the
// Save button.
if ($form_id == 'comment_form') {
$form['buttons']['submit'] = $form['submit'];
$form['buttons']['submit']['#submit'] = $form['#submit'];
$form['buttons']['submit']['#weight']--;
// left-most
}
if (strpos($form_id, 'workflow_tab_form') !== 0 && ($label = variable_get('workflow_extensions_default_save_button_label', ''))) {
$form['buttons']['submit']['#value'] = workflow_extensions_replace_state_name_tokens($label, $current_state_name);
}
unset($form['submit']);
// the button
//unset($form['#submit']); // don't remove handler, [#1097328]
}