Getting the workflow associated to a node type
-
21-02-2021 - |
문제
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.
해결책
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.
제휴하지 않습니다 drupal.stackexchange