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

joglin’s picture

Menu module has the same bug.

/**
 * Implements hook_node_delete().
 */
function menu_node_delete($node) {
  // Delete all menu module links that point to this node.
  $result = db_query("SELECT mlid FROM {menu_links} WHERE link_path = :path AND module = 'menu'", array(':path' => 'node/' . $node->nid), array('fetch' => PDO::FETCH_ASSOC));
  foreach ($result as $m) {
    menu_link_delete($m['mlid']);
  }
}
agentrickard’s picture

Status: Active » Postponed

Yeah, I think this is a warning more than anything else. I haven't actually seen an instance where this bug has bitten anyone.