Great module! But ...
I tested og_menu together with panels. I got a 'huge' amount of error messages Warning: preg_match () expects parameter 2 to Be string, array given in / var / www / html / includes / bootstrap.inc on line 777th
I think this is due to incompatibility of output of the og_menu_get_menus with 'menu system' in Drupal core. My problem solved small change:
Original:

function og_menu_get_menus($gids = NULL, $user = NULL) {
  if (!$user) {
    global $user;
  }
  if (!$gids) {
    $gids = array_keys($user->og_groups);
  }
  $menus = array();
  if ($gids) {
    $result = db_query("SELECT * FROM {menu_custom} m INNER JOIN {og_menu} om ON m.menu_name = om.menu_name WHERE om.gid IN (". db_placeholders($gids, "int"). ") ORDER BY m.title", $gids);
    while ($menu = db_fetch_array($result)) {
        $menus[] = $menu;
    }
  }
  return $menus;
}

My modification:

function og_menu_get_menus($gids = NULL, $user = NULL, $og_module = FALSE) {
  if (!$user) {
    global $user;
  }
  if (!$gids) {
    $gids = array_keys($user->og_groups);
  }
  $menus = array();
  if ($gids) {
    $result = db_query("SELECT * FROM {menu_custom} m INNER JOIN {og_menu} om ON m.menu_name = om.menu_name WHERE om.gid IN (". db_placeholders($gids, "int"). ") ORDER BY m.title", $gids);
    while ($menu = db_fetch_array($result)) {
      if ($og_module == FALSE) {
        // that's the trick
        $menus[$menu['m.menu_name']] = $menu['m.title'];
      } else {
        $menus[] = $menu;
      }
    }
  }
  return $menus;
}

All instances of the function in og_module are then called og_menu_get_menus( , , TRUE). It works without problems (for my site :-)).

Regards Tomas

CommentFileSizeAuthor
#7 og_menu-793854.1.patch3.79 KBevoltech
#2 candice.png31.03 KBevoltech

Comments

penguininja’s picture

This error also occurs when using OG Menu with the Menu Block module (http://drupal.org/project/menu_block). I'm using a clean 6.16 install, Organic Groups 6.x-2.1, OG Menu 6.x-2.0, and Menu Block 6.x-2.3.

Steps to reproduce:

1. Required modules: OG, OG Menu, Menu Block
2. Create an organic group with an OG menu ("Enable menu for this group" box is checked)
3. Go to /admin/settings/menu_block
4. For each group with an OG menu, there will be a menu with a blank title in the list*
5. There will also be 2 "warning: preg_match() expects parameter 2 to be string, array given in...bootstrap.inc on line 777." errors for each OG Menu

* Note: This only seems to occur for the groups that the logged-in user is a member of. Also, this error does not appear to affect the functionality of either Og Menu or Menu Block.

Is this on the radar at all? Thanks for your time, it would be great to be able to use OG Menu and Menu Block together without this error.

evoltech’s picture

StatusFileSize
new31.03 KB

I was able to reproduce the error described by penguininja in #1

bonobo’s picture

Title: Strange ERROR: warning: preg_match() expects parameter 2 to be string » warning: preg_match() expects parameter 2 to be string

Changing title to more remove editorial comments on the error :)

evoltech’s picture

The problem seems to be in menu_block.module:menu_block_get_all_menus()

// We're generalizing menu's menu_get_menus() by making it into a hook.
// Retrieve all the menu names provided by hook_get_menus().
$all_menus = module_invoke_all('get_menus');
$all_menus = menu_get_menus('get_menus');

The error message does not happen. I see that the solution above for og_menu_get_menus would solve this problem as well, but maybe the issue is that the menu_block module is actually implementing hook_get_menus (not menu.module as I initially expected), and og_menu unintentionally implements it?

jide’s picture

Status: Active » Needs work

Thank you everyone for digging into this issue.

This is definitely because og_menu uses a function named og_menu_get_menus() which conflicts with hook_get_menus(). I'll have to rename og_menu_get_menus() to _og_menu_get_menus() as I should have from the start, although a hook named hook_get_menus() seems kind of dangerous to me.

As a quick fix until I provide an update, you could replace all occurrences of "og_menu_get_menus" by "_ og_menu_get_menus" in og_menu.module.

jgraham’s picture

Title: warning: preg_match() expects parameter 2 to be string » og_menu inadvertently implements hook_get_menus()

Changed ticket title to reflect actual problem.
The symptom is a preg_match() warning such as:

warning: preg_match() expects parameter 2 to be string

Also, I would recommend the name change to 'og_menu_get_custom_menus' rather than '_og_menu_get_menus' as from my experience '_' pre-pended to a function name typically means 'reserved for internal use' and not to resolve namespace collisions.

evoltech’s picture

Status: Needs work » Patch (to be ported)
StatusFileSize
new3.79 KB

Please see patch (against 6.x-2.x-dev? not 6.x-2.x) that fixes this issue by applying the changes recommended by jgraham in #6

penguininja’s picture

Evoltech's patch in comment #7 is working for me. I am not seeing any more preg_match errors or blank menu entries, and both Menu Block and OG Menu appear to be functioning correctly. Thanks!

penguininja’s picture

Status: Patch (to be ported) » Reviewed & tested by the community

FYI, I tested this patch successfully against 6.x-2.0.

bonobo’s picture

From the release page, the dev release and the point release appear to be the same code, and both were released on the same day.

jide’s picture

Status: Reviewed & tested by the community » Fixed

Fixed in CVS. I renamed the function og_menu_get_custom_menus() instead.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

fuerst’s picture

Just for the files: At least in og_menu-2.4 the function og_menu_get_menus() is renamed to og_menu_get_group_menus().

rv0’s picture

Version: 6.x-2.0 » 7.x-2.x-dev

Also renaming this in D7 version for consistency.