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-&gt;entityTypeManager-&gt;getStorage("workflow")-&gt;loadByProperties(["id" =&gt; "editorial"])["editorial"];
$config = $workflow-&gt;getTypePlugin()-&gt;getConfiguration();
$config["entity_types"]["node"][] = "article";
$workflow-&gt;getTypePlugin()-&gt;setConfiguration($config);
$workflow-&gt;save();


At the moment I'm just setting contents types, for blocks it's something similar.
Greetings.