You are here

function og_menu_node_update in Organic Groups Menu (OG Menu) 7.3

Same name and namespace in other branches
  1. 7.2 og_menu.module \og_menu_node_update()

Implements hook_node_update().

File

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

Code

function og_menu_node_update($node) {
  if (og_is_group('node', $node)) {
    if (isset($node->og_menu)) {
      if ($node->og_menu) {
        $menu = og_menu_get_group_menus(array(
          'node' => array(
            $node->nid,
          ),
        ));
        if (empty($menu)) {
          menu_save(array(
            'menu_name' => 'menu-og-' . $node->nid,
            'title' => $node->title,
            'description' => t('OG Menu for') . ' ' . check_plain($node->title),
          ));
          og_menu_update_menu('menu-og-' . $node->nid, $node->nid, 'node');
        }
      }
      else {

        // Delete the associated menus.
        // We can't assume that the menu name is 'menu-og-[gid]'.
        // we need to look up menus associated with this group.
        $result = db_select('og_menu', 'm')
          ->fields('m', array(
          'menu_name',
        ))
          ->condition('gid', $node->nid, '=')
          ->condition('group_type', 'node', '=')
          ->execute();
        while ($record = $result
          ->fetchAssoc()) {
          $menu = menu_load($record['menu_name']);
          menu_delete($menu);
          og_menu_delete_menu($record['menu_name']);
        }
      }
    }
  }
}