You are here

function workflowfield_options_list in Workflow 7.2

Same name and namespace in other branches
  1. 7 workflow_field/workflowfield.field.inc \workflowfield_options_list()

Implements hook_options_list().

Callback function for the default Options widgets.

@todo: move to a class.

File

workflow_field/workflowfield.field.inc, line 294
Defines a Workflow field, widget and formatter. (copied from list field).

Code

function workflowfield_options_list($field, $instance, $entity_type, $entity) {
  global $user;

  // @todo #2287057: OK?
  // @todo: Perhaps global user is not always the correct user.
  // E.g., on ScheduledTransition->execute()? But this function is mostly used in UI.
  $options = array();
  if ($entity) {

    // Get the allowed new states for the entity's current state.
    $field_name = $field['field_name'];
    $sid = workflow_node_current_state($entity, $entity_type, $field_name);
    $state = workflow_state_load_single($sid);
    $options = $state
      ->getOptions($entity_type, $entity, $field_name, $user, FALSE);
  }
  else {

    // $field['settings']['wid'] can be numeric or named.
    if ($workflow = workflow_load_single($field['settings']['wid'])) {

      // There is no entity, E.g., on the Rules action "Set a data value".
      $state = new WorkflowState(array(
        'wid' => $workflow->wid,
      ));
      $options = $state
        ->getOptions('', NULL, '', $user, FALSE);
    }
  }
  return $options;
}