function og_menu_node_update in Organic Groups Menu (OG Menu) 7.2
Same name and namespace in other branches
- 7.3 og_menu.module \og_menu_node_update()
Implementation of hook_node_update()
File
- ./
og_menu.module, line 612 - Integrates Menu with Organic Groups. Lots of menu forms duplication in OG context.
Code
function og_menu_node_update($node) {
if (og_is_group_type('node', $node->type)) {
$og = og_get_group('node', $node->nid, FALSE, array(
OG_STATE_ACTIVE,
OG_STATE_PENDING,
));
if (isset($node->og_menu)) {
if ($node->og_menu) {
$menu = og_menu_get_group_menus(array(
$og->gid,
));
if (empty($menu)) {
menu_save(array(
'menu_name' => 'menu-og-' . $og->gid,
'title' => $node->title,
'description' => t('OG Menu for') . ' ' . $node->title,
));
og_menu_update_menu('menu-og-' . $og->gid, $og->gid);
}
}
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_query('SELECT menu_name FROM {og_menu} WHERE gid = :gid', array(
':gid' => $og->gid,
))
->fetchCol();
foreach ($result as $menu_name) {
menu_delete(array(
'menu_name' => $menu_name,
'title' => $node->title,
'description' => t('OG Menu for') . ' ' . $node->title,
));
og_menu_update_menu($menu_name);
}
}
}
// else = programmatic node save, do nothing.
}
}