I have the following menu in my system.


The parent menu-link connects to a node whose ID is 58. All the sub menu-links have a parent ID equal to 58.

I need to find the main and the sub-menus using 58, but I have been unsuccessful at locating the a table that contains that information.

How can I list the nodes that share a particular menu ID?

  • Are you actually trying to find just the nodes that are children of a particular parent menu item and do something with them? or are you just trying to display all of a particular menu item's children (whether the child menu items point to nodes or other)?
    – sonfd
    Oct 8, 2021 at 12:40
  • Yes. I'm trying to get the nodes to do something with them The parent and offspring node IDs will go into some logic else where on the site.
    – sisko
    Oct 8, 2021 at 15:47
  • @sisko did you have a chance to try my suggested answer? Oct 14, 2021 at 16:30

1 Answer 1


The menu_link_content entity definition contains information related to your question; namely, the database table that contain the parent-child relation would be menu_link_content_data.

Below is a code sample that would deliver an array of node ids given a parent node, provided that there is a menu link attached to the node. This code uses Drupal's APIs instead of SQL queries.


// Get the root based on a given node, e.g. node 58.
$menu_link_root_entities = \Drupal::entityTypeManager()
      'link'  => [
        'uri' => 'entity:node/58'
$menu_link_root = reset($menu_link_root_entities);

// Need to call this in order to instantiate the tree_storage service.
$menu_tree = \Drupal::menuTree();
// Get menu link content entities based on their parent property.
$menu_links = \Drupal::service('menu.tree_storage')->loadByProperties([
    // Need a filter value like menu_link_content:8031d182-7a0b-4798-839a-6c66bdd1f27b
    'parent' => 'menu_link_content:' . $menu_link_root->uuid(),
]) ?: [];

$node_ids = array_map(function($v){
    return $v['route_parameters']['node'];
}, $menu_links);

Hope this helps, good luck!

  • This works fine in drupal 9.5 but I couldn't get it to work in drupal 10.1. I get the following error message "Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "menu.tree_storage". in Drupal\Component\DependencyInjection\Container->get() (line 157 of core/lib/Drupal/Component/DependencyInjection/Container.php)."
    – hobbsie
    Jul 17, 2023 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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