You are here

function workflow_get_workflows_by_type in Workflow 7.2

Same name and namespace in other branches
  1. 8 workflow.module \workflow_get_workflows_by_type()
  2. 7 workflow.module \workflow_get_workflows_by_type()

Get a specific workflow, given a Node type. Only one workflow is possible per node type.

@todo: support multiple workflows per entity.

Parameters

string $entity_bundle: A node type (a.k.a. entity bundle).

string $entity_type: An entity type. This is passed when also the Field API must be checked.

Return value

A Workflow object, or FALSE if no workflow is retrieved.

Caveat: gives undefined results with multiple workflows per entity.

7 calls to workflow_get_workflows_by_type()
workflownode_node_insert in workflow_node/workflownode.module
Implements hook_node_insert().
workflownode_node_load in workflow_node/workflownode.module
Implements hook_node_load().
workflownode_tokens in workflow_node/workflownode.tokens.inc
Implements hook_tokens().
workflow_vbo_next_state_action in workflow_vbo/actions/next.action.inc
Implements a Drupal action. Move a node to the next state in the workflow.
_workflownode_form_alter in workflow_node/workflownode.module
Helper function to implement hook_form_alter().

... See full list

File

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

Code

function workflow_get_workflows_by_type($entity_bundle, $entity_type = 'node') {
  static $map = array();
  if (!isset($map[$entity_type][$entity_bundle])) {
    $wid = FALSE;
    $map[$entity_type][$entity_bundle] = FALSE;

    // Check the Node API first: Get $wid.
    if (module_exists('workflownode') && ($type_map = workflow_get_workflow_type_map_by_type($entity_bundle))) {

      // Get the workflow by wid.
      $wid = $type_map->wid;
    }

    // If $entity_type is set, we must check Field API. Data is already cached by core.
    if (!$wid && isset($entity_type)) {
      foreach (_workflow_info_fields(NULL, $entity_type, $entity_bundle) as $field_name => $field_info) {
        $wid = $field_info['settings']['wid'];
      }
    }

    // Set the cache with a workflow object.
    if ($wid) {

      // $wid can be numeric or named.
      $workflow = workflow_load_single($wid);
      $map[$entity_type][$entity_bundle] = $workflow;
    }
  }
  return $map[$entity_type][$entity_bundle];
}