Closed (fixed)
Project:
Workflow
Version:
6.x-1.0-beta1
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
29 Jul 2008 at 16:12 UTC
Updated:
14 Aug 2008 at 22:25 UTC
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
Comment #1
jvandyk commentedGreat cruft removal. Thanks, committed to HEAD.
Comment #2
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.