Ok finally i did this way:
public function build(RouteMatchInterface $route_match) : Breadcrumb {
$breadcrumb = new Breadcrumb();
$this->menu_link_manager = \Drupal::service('plugin.manager.menu.link');
$node_id = 22; //I use a query to get the entities according to the routeMatch argument
$results = $this->menu_link_manager->loadLinksByRoute('entity.node.canonical', array('node' => $node_id));
foreach ($results as $result){
if ($result->getMenuName() == "main"){
$links = $this->_build_links($result,[Link::createFromRoute(t('Home'), '<front>')]);
//here i use just a string 'Home', ideally this string should be taken from breadcrumbs\site settings.
}
}
$breadcrumb->setLinks($links);
return $breadcrumb;
}
private function _build_links($menu_item, $links){
if ($menu_item->getParent() && $parent = $this->menu_link_manager->createInstance($menu_item->getParent())) {
$links = $this->_build_links($parent, $links);
}
$title = $menu_item->getTitle();
$routeName = $menu_item->getRouteName();
$routeParameters = $menu_item->getRouteParameters();
$options = $menu_item->getOptions();
$links[] = Link::createFromRoute($title,$routeName,$routeParameters,$options);
return $links;
}
I was pretty close to hooking up with the code of menu_breadcrumbs but I think there is an issue with the code there that prevents this kind of use
see issues/3026188
My code is still not perfect and I would really still want to find a way to access and chain the breadcrumbs of "parent" node(node/22) in a more general way.