I am trying to change the content moderation state from draft
to submitted
programatically. The Content Moderation module adds a field to content types with a dropdown to change the state, but I want to hide this field from users and instead show a custom submit handler that changes the form state.
I can change the default value of the moderation field with code like this:
$form['moderation_state']['widget'][0]['state']['#default_value'] = "submitted";
But, how do I change the value for the content moderation field using $form_state
in the submit handler?
$form_state->setValue('moderation_state', 'submitted');`
does not work like it does for fields.
Here is the debug output for kint($form['moderation_state']['widget'][0])
: