You are here

function workflow_node_form in Workflow 5.2

Same name and namespace in other branches
  1. 5 workflow.module \workflow_node_form()
  2. 6.2 workflow.module \workflow_node_form()
  3. 6 workflow.module \workflow_node_form()
  4. 7 workflow.module \workflow_node_form()

Add the actual form widgets for workflow change to a form definition.

Parameters

$form: A form definition array.

$name: The name of the workflow.

$current: The state ID of the current state.

$choices: An array of possible target states.

2 calls to workflow_node_form()
workflow_form_alter in ./workflow.module
Modify the node form to add the workflow field.
workflow_tab_form in ./workflow.module
Creates form definition of the workflow editing form.

File

./workflow.module, line 444

Code

function workflow_node_form(&$form, $title, $name, $current, $choices, $timestamp = NULL, $comment = NULL) {

  // No sense displaying choices if there is only one choice.
  if (sizeof($choices) == 1) {
    $form['workflow'][$name] = array(
      '#type' => 'hidden',
      '#value' => $current,
    );
  }
  else {
    $form['workflow'][$name] = array(
      '#type' => 'radios',
      '#title' => $title,
      '#options' => $choices,
      '#name' => $name,
      '#parents' => array(
        'workflow',
      ),
      '#default_value' => $current,
    );

    // Display scheduling form only if a node is being edited and user has
    // permission. State change cannot be scheduled at node creation because
    // that leaves the node in the (creation) state.
    if (!(arg(0) == 'node' && arg(1) == 'add') && user_access('schedule workflow transitions')) {
      $scheduled = $timestamp ? 1 : 0;
      $timestamp = $scheduled ? $timestamp : time();
      $form['workflow']['workflow_scheduled'] = array(
        '#type' => 'radios',
        '#title' => t('Schedule'),
        '#options' => array(
          t('Immediately'),
          t('Schedule for state change at:'),
        ),
        '#default_value' => $scheduled,
      );
      $form['workflow']['workflow_scheduled_date'] = array(
        '#type' => 'date',
        '#default_value' => array(
          'day' => format_date($timestamp, 'custom', 'j'),
          'month' => format_date($timestamp, 'custom', 'n'),
          'year' => format_date($timestamp, 'custom', 'Y'),
        ),
      );
      $hours = format_date($timestamp, 'custom', 'H:i');
      $form['workflow']['workflow_scheduled_hour'] = array(
        '#type' => 'textfield',
        '#description' => t('Please enter a time in 24 hour (eg. HH:MM) format. If no time is included, the default will be midnight on the specified date. The current time is: ') . format_date(time()),
        '#default_value' => $scheduled ? $hours : NULL,
      );
    }
    $form['workflow']['workflow_comment'] = array(
      '#type' => 'textarea',
      '#title' => t('Comment'),
      '#description' => t('A comment to put in the workflow log.'),
      '#default_value' => $comment,
      '#rows' => 2,
    );
  }
}