Unset widget tab from media browser programmatically Need to unset a widget tab from media browser based on the condition of media type supported by the field.

Media types: Image and Video.

For example, There is a field which references image media type only. When the media browser appears on the form, it displays create embed tab as well to embed the videos.

As the field doesn’t reference the video media type, need to unset the tab programmatically to help the content author.

I have tried the form alter, but I don't get any information about the media type referenced by the field in the hook.
It should be possible with some code like this:

function MY_MODULE_form_entity_browser_MY_FORM_form_alter(&amp;$form, FormStateInterface $form_state, $form_id) {   
  $form['#pre_render'][] = 'MY_MODULE_pre_render';  
}

function MY_MODULE_pre_render($element) {
  kint($element); //Find the tab you want to remove.
  if (...) {
    unset($element['...']);
  }
  return $element;
}


Another commonly used solution is to create 2 or 3 media browsers depending on your needs.
So you will have an image media browser, a video media browser and an image + video media browser.

Then you just select which one to use in the field settings.