You are here

function workflow_field_choices in Workflow 6

Same name and namespace in other branches
  1. 5.2 workflow.module \workflow_field_choices()
  2. 5 workflow.module \workflow_field_choices()
  3. 6.2 workflow.module \workflow_field_choices()
  4. 7.2 workflow.deprecated.inc \workflow_field_choices()
  5. 7 workflow.node.inc \workflow_field_choices()

Get the states current user can move to for a given node.

Parameters

object $node: The node to check.

Return value

Array of transitions.

6 calls to workflow_field_choices()
workflow_form_alter in ./workflow.module
Implementation of hook_form_alter().
workflow_nodeapi in ./workflow.module
Implementation of hook_nodeapi().
workflow_select_next_state_action in workflow_actions/workflow_actions.module
Implementation of a Drupal action. Move a node to the next state in the workfow.
workflow_tab_form in ./workflow.pages.inc
Form builder. Allow workflow state change and scheduling from workflow tab.
workflow_token_values in ./workflow.module
Implementation of hook_token_values().

... See full list

File

./workflow.module, line 477
Support workflows made up of arbitrary states.

Code

function workflow_field_choices($node) {
  global $user;
  $wid = workflow_get_workflow_for_type($node->type);
  if (!$wid) {

    // No workflow for this type.
    return array();
  }
  $states = workflow_get_states($wid);
  $roles = array_keys($user->roles);
  $current_sid = workflow_node_current_state($node);

  // If user is node author or this is a new page, give the authorship role.
  if ($user->uid == $node->uid && $node->uid > 0 || arg(0) == 'node' && arg(1) == 'add') {
    $roles += array(
      'author' => 'author',
    );
  }
  if ($user->uid == 1) {

    // Superuser is special.
    $roles = 'ALL';
  }
  $transitions = workflow_allowable_transitions($current_sid, 'to', $roles);

  // Include current state if it is not the (creation) state.
  if ($current_sid == _workflow_creation_state($wid)) {
    unset($transitions[$current_sid]);
  }
  return $transitions;
}