How to load the immediate parent link in a preprocess function?
I think you can do it with the 'plugin.manager.menu.link' service:

$link = $this-&gt;menuActiveTrail-&gt;getActiveLink();

if(!empty($link-&gt;getParent())) {
  $parent_link = Drupal::service('plugin.manager.menu.link')-&gt;createInstance($link-&gt;getParent());
  $menu_item = MenuLinkContent::load($parent_link-&gt;getMetaData()['entity_id']);
}


This way you don't have to replace the prefix.