You are here

function og_menu_nodeapi in Organic Groups Menu (OG Menu) 6

Same name and namespace in other branches
  1. 6.2 og_menu.module \og_menu_nodeapi()

Implementation of hook_nodeapi().

File

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

Code

function og_menu_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch ($op) {
    case 'insert':
      db_query("INSERT INTO {menu_custom} (menu_name, title, description) VALUES ('%s', '%s', '%s')", 'menu-og-' . $node->nid, $node->title, t('Menu for') . ' ' . check_plain($node->title));
      og_menu_update_menu('menu-og-' . $node->nid, $node->nid);
      break;
    case 'update':
      if (!$node->og_menu) {
        db_query("DELETE FROM {menu_custom} WHERE menu_name = '%s'", 'menu-og-' . $node->nid);
        og_menu_update_menu('menu-og-' . $node->nid);
      }
      else {
        $menu = og_menu_get_menus(array(
          $node->nid,
        ));
        if (empty($menu)) {
          db_query("INSERT INTO {menu_custom} (menu_name, title, description) VALUES ('%s', '%s', '%s')", 'menu-og-' . $node->nid, $node->title, t('Menu for') . ' ' . check_plain($node->title));
          og_menu_update_menu('menu-og-' . $node->nid, $node->nid);
        }
      }
      break;
    case 'prepare':
      $node->og_menu = og_menu_get_menus(array(
        $node->nid,
      ));
      break;
    case 'delete':
      db_query("DELETE FROM {menu_custom} WHERE menu_name = '%s'", 'menu-og-' . $node->nid);
      og_menu_update_menu('menu-og-' . $node->nid);
      break;
  }
}