Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In D7, due to alter hooks, the following code can be considered naiive, and needs a refactor:
/**
* Implements hook_menu_link_insert().
*/
function menu_node_menu_link_insert($link) {
if ($link['router_path'] != 'node/%' || !isset($link['mlid'])) {
return;
}
$nid = str_replace('node/', '', $link['link_path']);
if ($node = node_load($nid)) {
menu_node_record_save($node, $link);
}
}
This is because modules may alter the canonical router_path of entities.
We may also need to refactor the update hook to ensure that the router_path is still viable on update.
Comments
Comment #1
joglin CreditAttribution: joglin commentedMenu module has the same bug.
Comment #2
agentrickardYeah, I think this is a warning more than anything else. I haven't actually seen an instance where this bug has bitten anyone.