You are here

function workflow_cleanup_form in Workflow 7.2

Same name and namespace in other branches
  1. 7 workflow_cleanup/workflow_cleanup.module \workflow_cleanup_form()

The main cleanup page.

1 string reference to 'workflow_cleanup_form'
workflow_cleanup_menu in workflow_cleanup/workflow_cleanup.module
Implements hook_menu().

File

workflow_cleanup/workflow_cleanup.pages.inc, line 10
Contains an Admin page to delete obsolete states and transitions.

Code

function workflow_cleanup_form($form, &$form_state) {
  $form = array();

  // Get all of the states, indexed by sid.
  $states = $orphans = $inactive = array();
  foreach ($states = workflow_state_load_multiple() as $state) {

    // Does the associated workflow exist?
    if (!$state
      ->getWorkflow()) {
      $orphans[$state->sid] = $state
        ->getName();
    }
    else {

      // Is the state still active?
      if (!$state
        ->isActive()) {
        $inactive[$state->sid] = $state
          ->getName();
      }
    }
  }
  $form['#workflow_states'] = $states;
  $form['no_workflow'] = array(
    '#type' => 'container',
    '#title' => t('Orphaned States'),
    '#description' => t('These states no longer belong to an existing workflow.'),
    '#tree' => TRUE,
  );
  foreach ($orphans as $sid => $name) {
    $form['no_workflow'][$sid]['check'] = array(
      '#type' => 'checkbox',
      '#return_value' => $sid,
    );
    $form['no_workflow'][$sid]['name'] = array(
      '#type' => 'markup',
      '#markup' => check_plain($name),
    );
  }
  $form['inactive'] = array(
    '#type' => 'container',
    '#title' => t('Inactive (Deleted) States'),
    '#description' => t('These states belong to a workflow, but have been marked inactive (deleted).'),
    '#tree' => TRUE,
  );
  foreach ($inactive as $sid => $name) {
    $form['inactive'][$sid]['check'] = array(
      '#type' => 'checkbox',
      '#return_value' => $sid,
    );
    $form['inactive'][$sid]['name'] = array(
      '#type' => 'markup',
      '#markup' => check_plain($name),
    );
    $form['inactive'][$sid]['wf'] = array(
      '#type' => 'markup',
      '#markup' => !empty($sid) ? check_plain($states[$sid]
        ->getWorkflow()
        ->getName()) : '',
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Delete selected states'),
  );
  return $form;
}