Content Moderation: how to make a button to move between states? I want to allow authenticated users to fill out a node (Draft) and then, when they are ready, submit the node (to give it the Submitted state).  An admin will later decide whether or not to publish the node.

I'm experimenting with the improvements to the Content Moderation module on Drupal 8.4-rc2 (new UI is in the 8.4 series, so 8.3 and before will look different).

I have the following workflow states defined:


Draft
Submitted
Published


There is a transition called Submit to move from the Draft state to the Submitted state.  Authenticated users have permission to use this transition.

The problem is that the core UI for this looks very complicated.

This is a node edit page:


And this is a node view page:


I want to hide this moderation UI and instead provide users with a single button, "Submit for approval."

I hid the moderation and revision UI from auth users (only admin have permission to edit workflows) like this:

function mymodule_form_content_moderation_entity_moderation_form_alter(&amp;$form, FormStateInterface $form_state, $form_id) {
  $user = \Drupal::currentUser();
  if ( empty($user) || !($user-&gt;hasPermission('administer workflows')) ) {
    $form['#access'] = FALSE;
  }
}

function mymodule_form_node_mycontenttype_form_alter(&amp;$form, FormStateInterface $form_state, $form_id) {
  $user = \Drupal::currentUser();
  if ( empty($user) || !($user-&gt;hasPermission('administer workflows')) ) {
    $form['revision_information']['#access'] = FALSE;
    $form['moderation_state']['#access'] = FALSE;
  }
}

function mymodule_form_node_mycontenttype_edit_form_alter(&amp;$form, FormStateInterface $form_state, $form_id) {
  $user = \Drupal::currentUser();
  if ( empty($user) || !($user-&gt;hasPermission('administer workflows')) ) {
    $form['revision_information']['#access'] = FALSE;
    $form['moderation_state']['#access'] = FALSE;
  }
}


So this cleans up the UI and hides all the Content Moderation options.

But how do I create a button to move from one state to another?  Specifically, I want the bottom of the form to look like this:


Save button (saves the node in the same (Draft) workflow state)
New button that saves the node and activates the transition to the Submitted state


This is basically the same thing as what core does when it provides an option to Save as published and a second option to Save as unpublished-- I just want to do this with my workflow states.
I think you should be able to do something like this. (But I did not test).

The first code block adds an additional submit button and gives it a custom submit handler. (Button specific submit callbacks should run before form submit callbacks.)

function mymodule_form_TYPE_form_alter(&amp;$form, FormStateInterface $form_state, $form_id) {

  // Add second submit button (Also check if user can see this).
  $form['actions']['submit_publish'] = [
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Submit for approval'),
    '#submit' =&gt; ['mymodule_submit_callback'],
  ];
}


And the submit callback, which simply sets the new value for the moderation state. 

/**
 * Submit callback to submit for approval
 */
function mymodule_submit_callback(array &amp;$form, FormStateInterface &amp;$form_state) {
  $form_state-&gt;setValue('moderation_state', 'MODERATION STATE ID');
}