function workflow_get_workflows_by_type in Workflow 8
Same name and namespace in other branches
- 7.2 workflow.module \workflow_get_workflows_by_type()
- 7 workflow.module \workflow_get_workflows_by_type()
Get a specific workflow, given an entity type. Only one workflow is possible per node type. Caveat: gives undefined results with multiple workflows per entity. @todo Support multiple workflows per entity.
Parameters
string $entity_bundle: An entity bundle.
string $entity_type: An entity type. This is passed when also the Field API must be checked.
Return value
\Drupal\workflow\Entity\Workflow A Workflow object, or NULL if no workflow is retrieved.
File
- ./
workflow.module, line 550 - Support workflows made up of arbitrary states.
Code
function workflow_get_workflows_by_type($entity_bundle, $entity_type) {
static $map = [];
if (isset($map[$entity_type][$entity_bundle])) {
return $map[$entity_type][$entity_bundle];
}
$wid = FALSE;
if (isset($entity_type)) {
foreach (_workflow_info_fields(NULL, $entity_type, $entity_bundle) as $field_info) {
$wid = $field_info
->getSetting('workflow_type');
}
}
// Set the cache with a workflow object.
$map[$entity_type][$entity_bundle] = NULL;
if ($wid) {
$map[$entity_type][$entity_bundle] = Workflow::load($wid);
}
return $map[$entity_type][$entity_bundle];
}