You are here

function workbench_moderation_states_next in Workbench Moderation 7

Same name and namespace in other branches
  1. 7.3 workbench_moderation.module \workbench_moderation_states_next()

Provides a list of possible next states for this node.

This function is used in permissions checks, so it should never return disallowed transitions.

Parameters

$current_state: The current moderation state.

$account: The user object being checked.

$node: The node object being acted upon.

Return value

If the user may moderate a change, return an array of possible state changes. Otherwise, return FALSE.

8 calls to workbench_moderation_states_next()
workbench_moderation_form_node_form_alter in ./workbench_moderation.module
Implements hook_form_BASE_FORM_ID_alter().
workbench_moderation_get_moderation_links in ./workbench_moderation.module
Generates a list of links to available moderation actions.
workbench_moderation_messages in ./workbench_moderation.module
Sets status messages for a node.
workbench_moderation_moderate_form in ./workbench_moderation.module
Generates a moderation form for a node.
workbench_moderation_node_history_view in ./workbench_moderation.node.inc
Display a node's moderation history.

... See full list

File

./workbench_moderation.module, line 1584
Content moderation for Workbench.

Code

function workbench_moderation_states_next($current_state, $account = NULL, $node) {
  $states = FALSE;

  // Make sure we have a current state.
  if (!$current_state) {
    $current_state = workbench_moderation_state_none();
  }
  if (empty($account)) {
    $account = $GLOBALS['user'];
  }
  if (user_access('bypass workbench moderation', $account)) {

    // Some functions expect an array of $state => $state pairs.
    $states = workbench_moderation_state_labels();
    unset($states[$current_state]);
  }
  else {

    // Get a list of possible transitions.
    $select = db_select('workbench_moderation_transitions', 'transitions')
      ->condition('transitions.from_name', $current_state)
      ->fields('transitions', array(
      'to_name',
    ))
      ->fields('states', array(
      'label',
    ));
    $select
      ->join('workbench_moderation_states', 'states', 'transitions.to_name = states.name');
    $states = $select
      ->execute()
      ->fetchAllKeyed();

    // Checks whether the user has permission to make each transition. The
    // 'bypass workbench moderation' permission is accounted for in
    // workbench_moderation_state_allowed().
    if ($states) {
      foreach ($states as $machine_name => $label) {
        if (!workbench_moderation_state_allowed($account, $current_state, $machine_name, $node->type)) {
          unset($states[$machine_name]);
        }
      }
    }
  }
  $context = array(
    'account' => $account,
    'node' => $node,
  );
  drupal_alter('workbench_moderation_states_next', $states, $current_state, $context);
  return $states;
}