As an authorized backend user I would like to add symlinks to one or more Organic Groups Menus so I can cross link content between Drupal core and Organic Group Menus.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dangur created an issue. See original summary.

dangur’s picture

FileSize
2.07 KB
dangur’s picture

Fixes an undefined index php notice.

dangur’s picture

Checks if site has organic groups menu installed.

dangur’s picture

Closes parens, fixes fatal error

dangur’s picture

Returns value on node edit.

rv0’s picture

don't hardcode the menu naming structure, any menu can be enabled as an og_menu

jstamper’s picture

Here's an approach to the patch that's working for us.

  $nids = array();
  
  if(!empty($node->group_group[LANGUAGE_NONE])) {
    $nids[] = $node->nid; 
  }
  
  foreach ($node->og_group_ref[LANGUAGE_NONE] as $gid) {
    $nids[] = $gid['target_id'];
  }
  
  if(!empty($nids)) {  
    $result = db_query('SELECT menu_name FROM {og_menu} WHERE gid IN(:nids) ORDER By weight', array(':nids' => $nids));
    
    foreach ($result as $og_menu) {
      $menus[] = $og_menu->menu_name;
    }

    $wanted_menus = array_intersect_key(menu_get_menus(), array_flip($menus));
    $original_item = $item;
    $mpos = menu_parent_options($wanted_menus, $item, NULL);
    $item = $original_item;
    foreach ($mpos as $og_menu_key => $og_menu_value) {
      $menu_parent_options[$og_menu_key] = $og_menu_value;
    }
    // Checks if menu and parent values exist.
    if (isset($item['menu_name']) && isset($item['plid'])) {
      // Sets default parent item.
      $menu_default_parent = "{$item['menu_name']}:{$item['plid']}";
      // Checks if item is new.
    } elseif (array_key_exists('new_item', $item)) {
      if ($item['new_item'] === TRUE) {
        if (is_array($menu_default_parent)) {
          // Sets menu parent options array to first element.
          reset($mpos);
          // Sets menu default parent to first menu option.
          $menu_default_parent = key($mpos);
        }
      }
    }    
  }
jstamper’s picture

A revised version that captures the create phase...

if(module_exists('og_menu')) {
    global $user;

    $nids = array(
    
    $groups = og_menu_get_node_groups('user', $user);
  
    if(!empty($groups)) {
      foreach($groups as $group) {
        $nids[] = $group;
      }
    }
      
    if(!empty($nids)) {  
      $result = db_query('SELECT menu_name FROM {og_menu} WHERE gid IN(:nids) ORDER By weight', array(':nids' => $nids));
  
      foreach ($result as $og_menu) {
        $menus[] = $og_menu->menu_name;
      }
  
      $wanted_menus = array_intersect_key(menu_get_menus(), array_flip($menus));
      $original_item = $item;
      $mpos = menu_parent_options($wanted_menus, $item, NULL);
      $item = $original_item;
      
      foreach ($mpos as $og_menu_key => $og_menu_value) {
        $menu_parent_options[$og_menu_key] = $og_menu_value;
      }
      
      // Checks if menu and parent values exist.
      if (isset($item['menu_name']) && isset($item['plid'])) {
        // Sets default parent item.
        $menu_default_parent = "{$item['menu_name']}:{$item['plid']}";
        // Checks if item is new.
      } elseif(array_key_exists('new_item', $item)) {
        if ($item['new_item'] === TRUE) {
          if (is_array($menu_default_parent)) {
            // Sets menu parent options array to first element.
            reset($mpos);
            // Sets menu default parent to first menu option.
            $menu_default_parent = key($mpos);
          }
        }
      }    
    }
  }
daniel_j’s picture

This patch is the same as the one in #6, but with the appropriate number of subdirectories so that `drush make` can auto-apply it.

daniel_j’s picture

FileSize
2.67 KB

The patch in #10 was occasionally resulting in these warnings:

Notice: Undefined property: stdClass::$og_group_ref in _nodesymlinks_form_field() (line 229 of .../sites/all/modules/contrib/nodesymlinks/nodesymlinks.inc).
Warning: Invalid argument supplied for foreach() in _nodesymlinks_form_field() (line 229 of .../sites/all/modules/contrib/nodesymlinks/nodesymlinks.inc).

The attached patch addresses this.