This is likely related to this issue (https://www.drupal.org/node/1361664).
I had Display Suite installed, accidentally set the "og_menu" field to the "Hidden" region so it didn't display.
I didn't notice it, then edited a couple of my groups, and ALL my OG menus disappeared.
I checked the issue queue, and found some issues with menus being deleted, but not under this specific circumstance, but I think it is related.
I have not dug deeply into the code, but believe the problem is here:
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']);
}
}
If the og_menu field is hidden (which means it isn't displayed) or is not displayed due to lack of perms, it STILL shows up in the $node object, but has a value of "0". This causes the node_update code to think the node was saved with the og_menu = False (which is NOT true), causing it to DELETE ALL THE MENUS.
For now, I have just uncommented the "delete" code (I'll delete the menus by hand if I want that done).
It has been a while since I have delved into the Field API code so I'm a bit rusty but I'm guessing somewhere a #default is set to "0" and that is the issue. It should not be set AT ALL so when the value is "hidden" it doesn't cause an accidental deletion.
If I get the gumption in the next few days and have the time to dive in and figure it out, I'll post a patch.
Or, if someone not so rusty on the Field API code wants to take a crack, that is fine too.
I just wanted folks to be aware that if you HIDE the og_menu field for ANY reason, and edit the node, it WILL delete all your OG menus for that OG Node (which is probably not what you want).
Andrew.
Comments
Comment #1
rv0 commentedThere are other ways to hide the menu
Check the settings for OG Menu:
Though this only appears if "Automatically create menu for new Organic Group" is on.
In any case, its a checkbox so the value is either 1 or 0
I don't know what the value is when display suite hides it. If you could tell me that, I can look into fixing this issue.
Comment #2
rv0 commented