$state->label(), '%title' => entity_label($entity_type, $entity), ) ); return confirm_form($args, $question, $return_uri, t('The workflow state will be changed.') ); } else { watchdog('workflow_revert', 'Invalid token', array(), WATCHDOG_ERROR); drupal_set_message(t('Invalid token. Your information has been recorded.'), 'error'); drupal_goto($return_uri); } } /** * Submit callback function. * * The function is magically called, due to its name
_submit. */ function workflow_revert_form_submit($form, &$form_state) { global $user; $previous_sid = $form['#previous_sid']; // $id = $form['#entity_id']; $entity = $form['#entity']; $entity_type = $form['#entity_type']; $field_name = $form['#field_name']; $comment = t('State reverted.'); $uri = entity_uri($entity_type, $entity); $return_uri = $uri['path']; // If Rules is available, signal the reversion. if (module_exists('rules')) { rules_invoke_event('workflow_state_reverted', $entity); } $current_sid = workflow_node_current_state($entity, $entity_type, $field_name); $transition = new WorkflowTransition(); $transition->setValues($entity_type, $entity, $field_name, $current_sid, $previous_sid, $user->uid, REQUEST_TIME, $comment); // Force the transition because it's probably not valid. $new_sid = workflow_execute_transition($entity_type, $entity, $field_name, $transition, TRUE); ($previous_sid == $new_sid) ? drupal_set_message($comment) : drupal_set_message(t('State could not be reverted.'), 'warning'); drupal_goto($return_uri . '/workflow'); }