0

Is it possible to get the menu item of a certain content type through the API?

The idea is to improve Markus Orenstrat solution to set the active trail based on the content type. As it stands it requires hardcoding the menu_tree id in the service.

 if ($bundle == 'blog') {
   $plugin_id = 'menu_link_content:a00a209d-075e-46a2-b200-e2d439d92228b';
 }

I figured this could be avoided since the administration area allows to assign a menu item to a content type.

enter image description here

1

That's stored in the third party settings of the node type.

$type = NodeType::load('article');
$type->getThirdPartySetting('menu_ui', 'parent')

See also menu_ui_get_menu_link_defaults().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.