You are here

function workflow_form_alter in Workflow 5

Same name and namespace in other branches
  1. 8 workflow.form.inc \workflow_form_alter()
  2. 5.2 workflow.module \workflow_form_alter()
  3. 6.2 workflow.module \workflow_form_alter()
  4. 6 workflow.module \workflow_form_alter()
  5. 7.2 workflow.form.inc \workflow_form_alter()

Generate a forms API compliant workflow field.

Parameters

object &$node:

Return value

array

File

./workflow.module, line 378

Code

function workflow_form_alter($form_id, &$form) {
  if (isset($form['type']) && $form['#base'] == 'node_form') {
    $node = $form['#node'];
    $choices = workflow_field_choices($node);
    $wid = workflow_get_workflow_for_type($node->type);
    $states = workflow_get_states($wid) + array(
      t('(creation)'),
    );
    $current = workflow_node_current_state($node);
    $min = $states[$current] == t('(creation)') ? 1 : 2;
    if (count($choices) < $min) {

      // bail out if user has no new target state(s)
      return;
    }
    $name = check_plain(workflow_get_name($wid));

    // if the current node state is not one of the choices, autoselect first choice
    // we know all states in $choices are states that user has permission to
    // go to because workflow_field_choices() has already checked that
    if (!isset($choices[$current])) {
      $array = array_keys($choices);
      $current = $array[0];
    }
    if (sizeof($choices) > 1) {
      $form['workflow'] = array(
        '#type' => 'fieldset',
        '#title' => $name,
        '#collapsible' => TRUE,
        '#collapsed' => FALSE,
        '#weight' => 10,
      );
    }

    // see if scheduling information is present
    if ($node->_workflow_scheduled_timestamp && $node->_workflow_scheduled_sid) {
      global $user;
      if (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) {
        $timezone = $user->timezone;
      }
      else {
        $timezone = variable_get('date_default_timezone', 0);
      }
      $current = $node->_workflow_scheduled_sid;

      // the default value should be the upcoming sid
      $timestamp = $node->_workflow_scheduled_timestamp;
      $comment = $node->_workflow_scheduled_comment;
    }
    workflow_node_form($form, $name, $name, $current, $choices, $timestamp, $comment);
  }
}