function workflow_admin_ui_states_form_submit in Workflow 7.2
Submission handler for the state form.
File
- workflow_admin_ui/
workflow_admin_ui.page.states.inc, line 249 - Provides an Admin UI page for the Workflow States.
Code
function workflow_admin_ui_states_form_submit($form, &$form_state) {
// Get the workflow id, then save it for the next round.
$workflow = $form_state['values']['workflow'];
$wid = $workflow->wid;
// Because the form elements were keyed with the item ids from the database,
// we can simply iterate through the submitted values.
foreach ($form_state['values']['states'] as $sid => $item) {
$item['sid'] = $sid;
$item['wid'] = $wid;
// Is there not a new state name?
if (empty($item['state'])) {
// No new state entered, so skip it.
continue;
}
// Reload $state from db, in case the states were changed by anyone else. And it is just as fast.
$state = $sid ? workflow_state_load_single($sid) : $workflow
->createState('');
// Does user want to deactivate the state (reassign current nodes)?
if ($sid > 0 && $item['status'] == 0 && $state
->isActive()) {
$new_sid = $item['reassign'];
$new_state = workflow_state_load_single($new_sid);
$args = array(
'%workflow' => $workflow
->getName(),
// check_plain() is run by t().
'%old_state' => $state
->getName(),
'%new_state' => isset($new_state) ? $new_state
->getName() : '',
);
if ($item['count'] > 0) {
if ($form['#last_mohican']) {
$new_sid = NULL;
// Do not reassign to new state.
$message = 'Removing workflow states from content in the %workflow.';
drupal_set_message(t($message, $args));
}
else {
// Prepare the state delete function.
$message = 'Reassigning content from %old_state to %new_state.';
drupal_set_message(t($message, $args));
}
}
// Delete the old state without orphaning nodes, move them to the new state.
$state
->deactivate($new_sid);
$message = 'Deactivated workflow state %old_state in %workflow.';
watchdog('workflow', $message, $args);
drupal_set_message(t($message, $args));
}
$state->state = $item['state'];
$state->name = $item['name'];
$state->status = $item['status'];
$state->weight = $item['weight'];
$state
->save();
}
drupal_set_message(t('The workflow was updated.'));
// $form_state['redirect'] = WORKFLOW_ADMIN_UI_PATH;
}