I was inspecting our logs today an noticed this warning occurring a few times

Warning: in_array() expects parameter 2 to be array, string given in context_menu_tree_add_active_path() (line 128 of /var/www/html/sites/all/modules/context_menu_block/context_menu_block.module).

Comments

amarcus’s picture

StatusFileSize
new1.08 KB

I'm not sure what line 128 is supposed to do. It appears that the code is expecting $active_path to be an array including elements such as "main-menu:taxonony/term/5" whereas it seems to actually just be "taxonomy/term/5".

Here's a patch that tests for for it to be an array or a string.

lexmccurry4x3’s picture

We also had a similar Warning, on the first two sites we updated from 7.x-3.1-b3 to 7.x-3.1.
However this warning was visible to the public on a few pages with missing content. Reverting to the Previous 7.x-3.1-b3 resolved this issue:

Warning: in_array() expects parameter 2 to be array, string given in context_menu_tree_add_active_path() (line 128 of sites/all/modules/context_menu_block/context_menu_block.module)

floown’s picture

Hello,

I have the same issu : message error : Warning : in_array() expects parameter 2 to be array, string given dans context_menu_tree_add_active_path() (ligne 128 dans /home/admin/web/mydomain.com/public_html/sites/all/modules/context_menu_block/context_menu_block.module).
I have try to apply the patch, but I can not :

patch -p1 < context_menu_block-2415167-2.patch
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/sites/all/modules/contrib/context_menu_block/context_menu_block.module b/sites/all/modules/contrib/context_menu_block/context_menu_block.module
|index e030226..c112c51 100644
|--- a/sites/all/modules/contrib/context_menu_block/context_menu_block.module
|+++ b/sites/all/modules/contrib/context_menu_block/context_menu_block.module
--------------------------
File to patch: context_menu_block.module
patching file context_menu_block.module
Hunk #1 FAILED at 124.
1 out of 1 hunk FAILED -- saving rejects to file context_menu_block.module.rej

I have try without -p1 parameter :

patch < context_menu_block-2415167-2.patch 
patching file context_menu_block.module
Hunk #1 FAILED at 124.
1 out of 1 hunk FAILED -- saving rejects to file context_menu_block.module.rej

Help please.

welly’s picture

Status: Active » Postponed (maintainer needs more info)

Latest versions of Drupal, Context, Menu Block and Context Menu Block are failing to report any errors or warnings. Can you try updating to the latest versions and let me know how you get on.

markplindsay’s picture

For the benefit of others who arrive here via Google, I am getting this as well with Drupal 7.52, Context 7.x-3.7, Menu block 7.x-2.7, and Context: Menu Block 7.x-3.1.

It's been a long while since I worked on the code that uses the context_menu_block module. So, like amarcus commented, I am not sure what line 128 is supposed to be doing either.

Rather than patch up the latest version I reverted to Context: Menu Block 7.x-3.1-beta3 and all is well once again.

wylbur’s picture

StatusFileSize
new728 bytes

The code in line 128 is using in_array, but is looking at a string. I used a strcmp function to compare see if the menu item is the same as the node alias. If this is true, the active menu trail is set.

If you are seeing this error, applying the patch will resolve the error, and set the active menu path correctly.

wylbur’s picture

StatusFileSize
new728 bytes

Adding patch file with commit number in name.

wylbur’s picture

Status: Postponed (maintainer needs more info) » Needs review
borisson_’s picture

Status: Needs review » Reviewed & tested by the community

I had the same error, applied the patch in #7 on the latest versions of core, context and context menu block and now it works.

borisson_’s picture

Status: Reviewed & tested by the community » Needs work

Looks like this patch is giving us problems on another path. So reverted it from my install. Will post back if I find a better solution.

borisson_’s picture

Looks like resaving the contexts with correct configuration fixed it for me, I removed this patch and it worked as it's supposed to. Should've figured that out the first time.

I think that means this issue is not needed, but not sure.

vuil’s picture

Version: 7.x-3.1 » 7.x-3.x-dev
Status: Needs work » Needs review
StatusFileSize
new6.34 KB

Resolve the issue with:

-    if (!empty($tree[$key]['link']['href']) && in_array($tree[$key]['link']['href'], $active_paths)) {
+    if (!empty($tree[$key]['link']['href']) && in_array($tree[$key]['link']['href'], $active_paths, TRUE)) {

Also update the all http://drupal.org/xxx with https://drupal.org/xxx.

  • vuil committed f793065 on 7.x-3.x
    Issue #2415167 by wylbur, vuil: Non-critical error showing in logs,...
vuil’s picture

Status: Needs review » Fixed

I close the issue as Fixed.

Status: Fixed » Closed (fixed)

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