0

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.

1

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');

$workflow->save();
| improve this answer | |
  • It works! Thank you for the solution. – Sudheesh S Babu Feb 27 at 10:28
  • Great!@SudheeshSBabu Feel free to accept the answer. – cchen Feb 27 at 14:39
0

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');
print_r($settings['entity_types']);

Output:

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

)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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