You are here

function menu_item_extras_form_menu_link_content_form_alter in Menu Item Extras 8.2

Implements hook_form_BASE_FORM_ID_alter().

File

./menu_item_extras.module, line 249
Manage fields for the menu items.

Code

function menu_item_extras_form_menu_link_content_form_alter(array &$form, FormStateInterface $form_state) {

  /** @var \Drupal\menu_link_content\Form\MenuLinkContentForm $form_object */
  $form_object = $form_state
    ->getBuildInfo()['callback_object'];

  /** @var \Drupal\menu_link_content\Entity\MenuLinkContent $entity */
  $entity = $form_object
    ->getEntity();
  $bundle = $entity
    ->bundle();
  foreach ($form['menu_parent']['#options'] as $option_id => $option) {
    if (strpos($option_id, $bundle) !== 0) {
      unset($form['menu_parent']['#options'][$option_id]);
    }
  }
}