How to assign a content type to a workflow programmatically?
문제
is there any way that by code can assign a type of content to a workflow? I have reviewed the workflow module but I have not managed to find a method or a service that allows me to do it.
What I am trying to emulate is the action that makes this modal (programmatically not visually):
The only way I have found is by manipulating the workflows.workflow.myworkflow.yml
Per I'm trying to find a cleaner way.
Does anybody have an idea?
해결책
I found a way, I would like to know your opinion about how to do it.
No doubt you have to take into account additional validations, but basically to save a type of content to a workflow would be something like this:
/** @var \Drupal\workflows\WorkflowInterface $workflow */
$workflow = $this->entityTypeManager->getStorage("workflow")->loadByProperties(["id" => "editorial"])["editorial"];
$config = $workflow->getTypePlugin()->getConfiguration();
$config["entity_types"]["node"][] = "article";
$workflow->getTypePlugin()->setConfiguration($config);
$workflow->save();
At the moment I'm just setting contents types, for blocks it's something similar. Greetings.