I see this question was asked for Drupal 7, but the menu_link table doesn't exist in Drupal 9.
Is there a SQL query for listing all nodes that are not assigned to a menu?
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI see this question was asked for Drupal 7, but the menu_link table doesn't exist in Drupal 9.
Is there a SQL query for listing all nodes that are not assigned to a menu?
In Drupal 9 can use this 'menu_link_content_data' table to find whether node has any reference as menu:
Snippet code for finding all nodes not referenced by a// Get all nodes.
$nids = \Drupal::entityQuery('node')
->execute();
if (isset($nids) && !empty($nids)) {
foreach($nids as $nid){
// Check nid has reference as menu
$rst = \Drupal::database()->select('menu_link_content_data', 'mn')
->fields('mn')
->condition('mn.link__uri', 'entity:node/'.$nid, '=')
->execute()
->fetchAll();
// If nid has no reference as menu then insert nid in $nodes[]
if(empty($rst)){
$nodes[] = $nid;
}
}
}