diff --git a/workflow.api.php b/workflow.api.php index 5e1a206..17a17af 100644 --- a/workflow.api.php +++ b/workflow.api.php @@ -21,9 +21,16 @@ */ function hook_workflow($op, $old_state, $new_state, $node, $force = FALSE) { switch ($op) { + case 'transition choice': + // The workflow module does nothing during this operation. + // This operation occurs when the list of available transitions + // is built. Your module's implementation could return FALSE + // here and disallow the presentation of the choice. + break; + case 'transition pre': // The workflow module does nothing during this operation. - // But your module's Implements the workflow hook could + // But your module's implementation of the workflow hook could // return FALSE here and veto the transition. break; diff --git a/workflow.module b/workflow.module index 7a66fc4..f774dbb 100644 --- a/workflow.module +++ b/workflow.module @@ -447,7 +447,7 @@ function workflow_node_view($node, $view_mode, $langcode) { // If we are at the terminal state, then don't show the change form. $choices = workflow_field_choices($node); - if (count($choices) == 1) { + if (count($choices) > 1) { if ($current == key($choices)) { return; } @@ -861,14 +861,23 @@ function workflow_field_choices($node, $force = FALSE) { $roles = 'ALL'; } - // workflow_allowable_transitions() does not return the entire transition row. Would like it to, but doesn't. + // Workflow_allowable_transitions() does not return the entire transition row. Would like it to, but doesn't. // Instead it returns just the allowable data as: // [tid] => 1 [state_id] => 1 [state_name] => (creation) [state_weight] => -50 $transitions = workflow_allowable_transitions($current_sid, 'to', $roles); + // Include current state if it is not the (creation) state. foreach ($transitions as $transition) { if ($transition->sysid != WORKFLOW_CREATION) { - $choices[$transition->state_id] = check_plain(t($transition->state_name)); + // Invoke a callback indicating that we are collecting state choices. Modules + // may veto a choice by returning FALSE. In this case, the choice is + // never presented to the user. + $result = module_invoke_all('workflow', 'transition choice', $current_sid, $transition->state_id, $node); + // Did anybody veto this choice? + if (!in_array(FALSE, $result)) { + // If not vetoed, add to list. + $choices[$transition->state_id] = check_plain(t($transition->state_name)); + } } } } diff --git a/workflow.pages.inc b/workflow.pages.inc index b95e920..101e286 100644 --- a/workflow.pages.inc +++ b/workflow.pages.inc @@ -175,25 +175,6 @@ function workflow_tab_form($form, $form_state, $node, $wid, $states, $current) { $choices = workflow_field_choices($node); $min = $states[$current] == t('(creation)') ? 1 : 2; - // Invoke a callback indicating a transition is about to occur. Modules - // may veto the transition by returning FALSE. - // In this case, the transition is not about to occur, but we want to - // know if it should be dropped from the list of choices. - if (empty($choices)) { - return; - }; - foreach ($choices as $sid => $name) { - if ($current == $sid) { - continue; - } - $result = module_invoke_all('workflow', 'transition pre', $current, $sid, $node); - // Stop if a module says so. - if (in_array(FALSE, $result)) { - // if vetoed, remove from list. - unset($choices[$sid]); - } - } - // Only build form if user has possible target state(s). if (count($choices) >= $min) { $workflow = workflow_get_workflow_type_map_by_type($node->type);