2 added 101 characters in body
source | link

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(&$form, FormStateInterface $form_state) {
  if (isset($form['link']['widget'][0]['uri'])) {
    $name = $form_state->getFormObject()->getEntity()->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.

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(&$form, FormStateInterface $form_state) {
  if (isset($form['link']['widget'][0]['uri'])) {
    $name = $form_state->getFormObject()->getEntity()->getMenuName();
    if ($name !== 'my-menu') {
      $form['show_mobile']['#access'] = FALSE;
      $form['svg_icon']['#access'] = FALSE;
    }
  }
}

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(&$form, FormStateInterface $form_state) {
  $name = $form_state->getFormObject()->getEntity()->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.

1
source | link

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(&$form, FormStateInterface $form_state) {
  if (isset($form['link']['widget'][0]['uri'])) {
    $name = $form_state->getFormObject()->getEntity()->getMenuName();
    if ($name !== 'my-menu') {
      $form['show_mobile']['#access'] = FALSE;
      $form['svg_icon']['#access'] = FALSE;
    }
  }
}