You are here

function menu_node_enable in Menu Node API 7

Same name and namespace in other branches
  1. 6 menu_node.install \menu_node_enable()

Implements hook_enable().

On module enable, populate the {menu_node} table based on existing menu items.

2 calls to menu_node_enable()
MenuNodeAPIBasicTestCase::testMenuNodeAPI in tests/menu_node.test
Tests for basic internal module functions.
menu_node_update_7100 in ./menu_node.install
Sync the {menu_node} table based on existing menu items.

File

./menu_node.install, line 46
Install file for Menu Node API.

Code

function menu_node_enable() {
  $result = db_query("SELECT ml.mlid, ml.link_path FROM {menu_links} ml INNER JOIN {menu_custom} mc ON ml.menu_name = mc.menu_name WHERE ml.link_path <> 'node/%' AND ml.router_path = 'node/%'");
  foreach ($result as $data) {
    $nid = str_replace('node/', '', $data->link_path);

    // Ensure that we did not grab any bad links accidentally.
    $check = (bool) db_query("SELECT COUNT(*) FROM {node} WHERE nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField();
    if ($check) {
      db_insert('menu_node')
        ->fields(array(
        'nid' => $nid,
        'mlid' => $data->mlid,
      ))
        ->execute();
    }
  }
}