You are here

function workflow_get_workflows_by_type in Workflow 7

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

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

Parameters

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

$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.

12 calls to workflow_get_workflows_by_type()
workflow_get_creation_state_by_type in ./workflow.deprecated.inc
Return the ID of the creation state given a content type.
workflow_node_current_state in ./workflow.module
Get the current state of a given node.
workflow_node_insert in ./workflow.node.inc
Implements hook_node_insert().
workflow_node_load in ./workflow.node.inc
Implements hook_node_load(). @TODO: Consider replacing with hook_entity_load().
workflow_node_previous_state in ./workflow.module

... See full list

File

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

Code

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

    // Check the Node API first: Get $wid.
    $type_map = workflow_get_workflow_type_map_by_type($entity_bundle);
    if ($type_map) {

      // 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 (field_info_instances($entity_type, $entity_bundle) as $field_name => $instance) {
        $field = field_info_field($instance['field_name']);
        if ($field['type'] == 'workflow') {
          $wid = $field['settings']['wid'];

          // @todo: $entity_bundle should be part of the WorkflowItem constructor, too.
          $field_item = new WorkflowItem($field, $instance, $entity_type, NULL);
        }
      }
    }

    // Set the cache with a workflow object.
    $map[$entity_type][$entity_bundle] = FALSE;
    if ($wid) {
      $workflow = Workflow::load($wid);

      // Load the WorkflowItem on the Workflow, for later reference.
      $workflow
        ->getWorkflowItem($field_item);
      $map[$entity_type][$entity_bundle] = $workflow;
    }
  }
  return $map[$entity_type][$entity_bundle];
}