How to hide custom fields on the menu item form? I've added two new fields to the menu item form (admin/structure/menu/item/{ID}/edit):

function modulename_entity_base_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type) {
  $fields = [];

  if($entity_type-&gt;id() == 'menu_link_content') {
    $fields['show_mobile'] = \Drupal\Core\Field\BaseFieldDefinition::create('boolean')
      -&gt;setLabel(t('Show in mobile menu bar.'))
      -&gt;setDescription(t('Toggles the display of the menu item in the menu bar at the bottom of pages in mobile view.'))
      -&gt;setDisplayOptions('form', [
        'type' =&gt; 'boolean_checkbox',
        'weight' =&gt; '0',
        'settings' =&gt; [
          'display_label' =&gt; TRUE,
        ],
      ])
      -&gt;setDisplayConfigurable('form', TRUE);

    $fields['svg_icon'] = \Drupal\Core\Field\BaseFieldDefinition::create('string')
      -&gt;setLabel(t('Mobile Menu Bar SVG Icon'))
      -&gt;setDescription(t('Select the icon you want the menu item to use in the mobile menu bar.'))
      -&gt;setDisplayOptions('form', [
        'type' =&gt; 'string',
        'weight' =&gt; '0',
        'settings' =&gt; [
          'display_label' =&gt; TRUE,
        ],
      ])
      -&gt;setDisplayConfigurable('form', TRUE);
  }

  return $fields;
}


But now I run into the issue, that I only need these fields for the main navigation menu, and thus want to remove or hide these on all other menu item forms.

Preferably I would like to keep it all to the module that adds the fields, and not have to create a custom admin theme just to visually hide them.

What should I look at to figure this one out? I've tried googling a lot of different combinations of the question, but have yet to find anything that remotely looks like a solution.

Many thanks in advance to anyone who can point me in the right direction.
hook_entity_base_field_info will add fields to the entire entity. If you want to hide the fields in specific forms, you will have to use a form alter to hide the fields. The following code might be what you are looking for.

/**
 * Implement hook_form_FORM_ID_alter();
 */
function modulename_form_menu_link_content_menu_link_content_form_alter(&amp;$form, FormStateInterface $form_state) {
  $name = $form_state-&gt;getFormObject()-&gt;getEntity()-&gt;getMenuName();
  if ($name !== 'my-menu') {
    $form['show_mobile']['#access'] = FALSE;
    $form['svg_icon']['#access'] = FALSE;
  }
}


Change my-menu with the menu machine name of the only menu that you want the fields to appear on.