You are here

function og_menu_node_delete in Organic Groups Menu (OG Menu) 7.2

Same name and namespace in other branches
  1. 7.3 og_menu.module \og_menu_node_delete()

Implementation of hook_node_delete()

File

./og_menu.module, line 649
Integrates Menu with Organic Groups. Lots of menu forms duplication in OG context.

Code

function og_menu_node_delete($node) {
  if (og_is_group_type('node', $node->type)) {

    /* We need to be careful here. As users can create menu of whatever name,
     * we can't just delete from menu_custom looking for 'menu-og-' . [gid]
     * we need the gid of the group being deleted, see if its an og assosiated
     * menu from og_menu and then from that menu name, delete it.
     */
    $gid = og_get_group('node', $node->nid, FALSE, array(
      OG_STATE_ACTIVE,
      OG_STATE_PENDING,
    ))->gid;
    $results = db_query('SELECT menu_name FROM {og_menu} WHERE gid = :gid', array(
      ':gid' => $gid,
    ))
      ->fetchCol();

    // @todo This can be replaced with two db_delete queries
    foreach ($results as $menu_name) {
      db_query("DELETE FROM {menu_custom} WHERE menu_name = :mname", array(
        ':mname' => $menu_name,
      ));
      og_menu_update_menu($menu_name);
    }
  }
}