I'm struggling to figure out relationship between MenuLink and MenuLinkContent.
I'm creating new menu item like:
$menuItem = MenuLinkContent::create($params);
I can also query those elements like:
$menuItems = \Drupal::entityTypeManager()->getStorage('menu_link_content')->loadByProperties(['link.uri' => "internal:$path"]);
And that works well. Now if I need one of those object I want to get it's "siblings" - other object that share same parent. I have some weird structure:
$this->menuLinkManager = \Drupal::service('plugin.manager.menu.link');
$parentId = $menuItem->getParentId();
$parent = $this->menuLinkManager->createInstance($this->menuLinkManager->getDefinition($parentId)['id']);
And here I'm getting it's parent, but it's not MenuLinkContent object any more but instance of MenuLinkInterface. It has some fields as MenuLinkContent, but not all. I.e. I don't know how to get link path and similar.
There I can go further:
$siblings = $this->menuLinkManager->getChildIds($parent->getPluginId());
But main question is how to get MenuLinkContent when I have that MenuLinkInterface object?
Sub-question - why oh why is needed this parallel menu system and parallel menu classes?
MenuLinkContent
class implementsMenuLinkInterface
andContainerFactoryPluginInterface
.create()
method, is there any method you need that isn't defined in theMenuLinkInterface
interface?MenuLinkContent
class, which implements a plugin, with theMenuLinkContent
class that is an entity class.)