The following code is not correct:

  $workflow_name = $form_state['values']['wf_name'];
  if (array_key_exists('wf_name', $form_state['values']) && $workflow_name != '')  {
    // ...
  }

I would rewrite it in this way:

  if (isset($form_state['values']['wf_name']) && ($workflow_name = $form_state['values']['wf_name']) != '')  {
    // ...
  }

It does not make sense to use an array value, and then check if that value exists.

I don't have any evidence that Drupal takes off empty values from $form_state (if it's not said to do it), so the code could be simply (I report the full code):

/**
 * Submit handler for the workflow add form.
 * 
 * @see workflow_add_form()
 */
function workflow_add_form_submit($form, &$form_state) {
  if (($workflow_name = $form_state['values']['wf_name']) != '') {
    workflow_create($workflow_name);
    watchdog('workflow', 'Created workflow %name', array('%name' => $workflow_name));
    drupal_set_message(t('The workflow %name was created. You should now add states to your workflow.',
      array('%name' => $workflow_name)), 'warning'
    );
    $form_state['redirect'] = 'admin/build/workflow';
  }
}

As the form has already a validation function, the code could be further reduced to:

/**
 * Submit handler for the workflow add form.
 * 
 * @see workflow_add_form()
 */
function workflow_add_form_submit($form, &$form_state) {
  $workflow_name = $form_state['values']['wf_name'];
  workflow_create($workflow_name);
  watchdog('workflow', 'Created workflow %name', array('%name' => $workflow_name));
  drupal_set_message(t('The workflow %name was created. You should now add states to your workflow.', array('%name' => $workflow_name)), 'warning');
  
  $form_state['redirect'] = 'admin/build/workflow';
}

Comments

jvandyk’s picture

Status: Active » Fixed

Great cruft removal. Thanks, committed to HEAD.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.