I have a workflow to which I want to include entity/content types programmatically since these content types will be included to the system by the installation of the module to which they reside. I'm not sure how to load the specific workflow object and attach the entity type to that via code.

3 Answers 3


You need the addEntityTypeAndBundle method from ContentModerationInterface

A static way to implement it looks like:

$workflow = \Drupal::entityManager()->getStorage('workflow')->load([workflow_id]);

$workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'article');

  • It works! Thank you for the solution. Commented Feb 27, 2020 at 10:28
  • Great!@SudheeshSBabu Feel free to accept the answer.
    – cchen
    Commented Feb 27, 2020 at 14:39

I think you will need to load the workflow configuration as editable and modify the entity values in the type_settings.

Here's the quick code used to see how this was structured:

$config = \Drupal::config("workflows.workflow.editorial");
$settings = $config->get('type_settings');


    [node] => Array
            [0] => basic_page


This is now entityTypeManager rather than entityManager:

  // Add bundle to default workflow
  $workflow = \Drupal::entityTypeManager()->getStorage('workflow_type')->load('workflow_id');
  $workflow = Workflow::load('workflow_id');
  $workflow->getTypePlugin()->addEntityTypeAndBundle("entity_type_id", "entity_bundle_id");

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.