Content Moderation: Remove transition from select list programmatically How do I alter this select list programmatically in my module?



Permissions won't work here since all the roles can use the 'Request publish' transition, but the roles that can also use the 'Published' transition don't need to see 'Request publish'. I think the easiest way to make this change is to remove 'Request publish' from the dropdown list.

I'm working with hook_field_widget_form_alter()

The code that I'm trying to override is from formElement() in ModerationStateWidget.php.

Thanks.
Thanks @No Sssweat. You put me on the right track.

Since this is the node form, I opted to use hook_form_BASE_FORM_ID_alter(). 

/**
 * Implements hook_form_BASE_FORM_ID_alter() for node_form().
 */
function MY_MODULE_form_node_form_alter(&amp;$form, FormStateInterface $form_state) {
  $roles = \Drupal::currentUser()-&gt;getRoles();
  if (array_intersect(['role_1', 'role_2', 'role_3'], $roles)) {
    $options = isset($form['moderation_state']['widget']) ? $form['moderation_state']['widget'][0]['state']['#options'] : [];
    $options = array_diff_key($options, [
      'request_publish' =&gt; 'Request Publish',
      'request_unpublish' =&gt; 'Request unpublish',
      'request_delete' =&gt; 'Request Delete'
    ]);
    $form['moderation_state']['widget'][0]['state']['#options'] = $options;
  }
}