You are here

function workflow_get_workflows_full_object in Workflow 7

For use by CRUD only, gather everything into the CRUD formed object.

Parameters

$name: A string corresponding to a workflow object.

Return value

A fully loaded workflow object with type and statue mappings.

1 call to workflow_get_workflows_full_object()
workflow_features_export_render in ./workflow.features.inc
Implements hook_features_export_render().

File

./workflow.features.inc, line 185
Integrates workflow with features.

Code

function workflow_get_workflows_full_object($name) {
  if ($workflow = Workflow::getWorkflowByName($name)) {

    // Now we need to add data to the object for each state, an array of sub-objects.
    $options = array(
      'status' => 1,
    );

    // We only want active states for this export.
    $active_states = array();
    foreach (workflow_get_workflow_states_by_wid($workflow->wid, $options) as $index => $state) {
      $active_states[$state->sid] = $state->state;

      // Remove what we don't need to export.
      unset($state->sid);
      unset($state->wid);
      $workflow->states[] = $state;
    }

    // Now we need to add data to the export for each transition, an array of sub-objects.
    // Same goes for transitions, see above re: states.
    foreach ($active_states as $sid => $state) {

      // We're going to look everything up by the start state, not state involved, to avoid dupes.
      foreach (workflow_get_workflow_transitions_by_sid($sid, $options) as $transition) {

        // And to get the target state (by name) we need to look it up too.
        $target_state = workflow_get_workflow_states_by_sid($transition->target_sid);
        $transition->state = $state;
        $transition->target_state = $target_state->state;
        unset($transition->sid, $transition->target_sid);

        // Translate to role names so works cross install.
        $transition->roles = !empty($transition->roles) ? _workflow_rids_to_roles($transition->roles) : '';

        // Remove what we don't need to export.
        unset($transition->tid);
        $workflow->transitions[] = $transition;
      }
    }

    // Now we need to add data to the export for each type map, an array of sub-objects.
    // Same goes for node mappings, see above re: states.
    foreach (workflow_get_workflow_type_map_by_wid($workflow->wid) as $index => $type_map) {
      $workflow->node_types[] = $type_map->type;
    }
  }
  return $workflow;
}