3

How do i get the workflow entity associated to a certain node bundle? So far my approach has been to use EntityTypeManager to load the workflow config entity storage and trying to load the right workflow using loadByProperties() function,

$workflow = $this->entityTypeManager->getStorage('workflow')->loadByProperties();

except I don't know what properties I should be specifying or If I'm approaching this the right way.

1 Answer 1

4

Workflows are configuration entities so you can load them using their id:

$workflow = $this->entityTypeManager->getStorage('workflow')->load('workflow_machine_name');

Or "query" them using the Entity Query (check the Drupal 8 example shown here):

$query = $this->entityTypeManager->getStorage('workflow')->getQuery();
$query->condition('type_settings.entity_types.node', 'article', 'IN');
$workflows = $query->execute();

The condition is a proof-of-concept drawn from another config entity query but is the right path you need to test it agains the workflow entity schema.

2
  • Thank you! this worked for me, specifically getting the query object and specifying the condition. Executing the query gives you an array with workflow entity id. You can then use the id in the array to load the config entity using the example above $workflow = $this->entityTypeManager->getStorage('workflow')->load('workflow_machine_name'); .
    – Howard
    Commented Jan 16, 2020 at 16:14
  • Although this answer is very helpful, the query code isn't quite right and doesn't work. The condition should be $query->condition('type_settings.entity_types.node.*', 'article'); which filters the array type_settings.entity_types.node by the value 'article'. Commented Apr 15, 2022 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.