Hi,

After the last update I'm getting the following message in my log:

Notice: Trying to get property 'link' of non-object in template_preprocess_tb_megamenu_subnav() (line 269 of /code/modules/contrib/tb_megamenu/tb_megamenu.module)

It's kind of a tossup as to whether or not I'll see the submenu render.

CommentFileSizeAuthor
#10 3221150.diff495 bytesknaffles

Comments

mattbloomfield created an issue. See original summary.

mattbloomfield’s picture

Issue summary: View changes

So I may have pinned it down to this block of code:

- $tree = $this->menuTree->load($menu_name, (new MenuTreeParameters())->onlyEnabledLinks());
+ $tree = &drupal_static(__FUNCTION__);
+ if (is_null($tree)) {
+ $tree = $this->menuTree->load($menu_name, (new MenuTreeParameters())->onlyEnabledLinks());
+ }

in /src/TBMegaMenuBuild.php

If I reverse this so that just the first line is there, it renders the submenu just fine. Is there something else I can do to fix this?

themodularlab’s picture

Sorry to hear you are having issues with this. I'll try to do some testing today to see if I can re-create the issue and see what we can do to address it. Thanks for reporting issues!

themodularlab’s picture

Status: Active » Postponed (maintainer needs more info)

@mattbloomfield, I'm having trouble reproducing this issue. What version of drupal are you using? Are you using any custom preprocess functions or templates related to menus? Any other info that might be helpful to reproduce, such as steps, etc.? Depending on your level / amount of caching if you add a new menu item, particularly a sub menu item you may need to clear cache and/or after adding an item via the menu tree, update your menu's TB mega menu config (basically resaving it and then clearing cache).

I'm going to mark as needs more info for now. I'll keep testing to see if I can reproduce.

mattbloomfield’s picture

I'll try to do some testing to see if updating the config/flushing cache solves this. Nothing custom when it comes to menus.

mattbloomfield’s picture

I've tried flushing cache, re-saving config, and cloning the menu, but it's still not showing up. I've got this error in my log:

Notice: Trying to get property 'link' of non-object in template_preprocess_tb_megamenu_subnav() (line 270 of /code/modules/contrib/tb_megamenu/tb_megamenu.module)

themodularlab’s picture

Status: Postponed (maintainer needs more info) » Active

@mattbloomfield, Thanks for checking. We'll take another look at this and see if we can figure out what the issue is. Thanks for reporting!

jegan2668’s picture

Always, the first tb_megamenu was working fine. But the second tb_megamenu in same page, doesn't load the child menu items.
Notice: Trying to get property 'link' of non-object in template_preprocess_tb_megamenu_subnav() (line 271 of /app/docroot/modules/contrib/tb_megamenu/tb_megamenu.module).

Used the latest version of this module 8.x-1.5, which contains all the patches

knaffles’s picture

I was able to recreate this issue. Looking into it now.

knaffles’s picture

Version: 8.x-1.0 » 8.x-1.5
Status: Active » Needs review
StatusFileSize
new495 bytes

@ Jegan2668, can you try applying this patch and let me know if it fixes the issue for you? Thanks.

bertvivie’s picture

Hi in previous version it was possible to add a submenu based on a Block which was based on a view
In drupal 7 it was even easier, there you could add a submenu based on a view.

In the latest update this possibility seems to be disapeared
How can I fix this cause my site is partialy broken

bertvivie’s picture

After installing 8.x.1.5 on drupal 9.2.x where tb_megamenu was already installed and working with a submenu on block-views these submenus are gone (the block-views were in the layout blocks but disabled so they do not show up on the pages.
After enabling this block views they show up again.
But are also visible on all pages (unwanted)
Trick to solve this (with help from @themodularlab is to add a hidden region in the info.yml file (do not forget to clear cache after this step)
And move the block-views needed for the tb-megamenu to that region (in blocks) and keep them enabled
Be sure that this hidden region (us a clear name like hidden :)) is never rendered in one of the twig files.

This worked for me on production but when I tried this at my dev site I used another order with this steps ??
This resulted in a broken site with error:
Call to a member function access() on null in Drupal\tb_megamenu\TBMegaMenuBuilder->loadEntityBlock() (line 133 of modules\tb_megamenu\src\TBMegaMenuBuilder.php).

Tried different approaches to remove this error nothing works and luckily I was in admin mode so I could reach the site afterall
This is how I solved this:
In the Php file see above I commented the if on line 133 after that step I could start tb_megamenu maintenance removed the blocks from the submenu and after that step Restored the if situation.

I Think this if statement should be made null safe in the php before other users ran in the same problems.

mattbloomfield’s picture

It looks like both the hidden region and the patch in #10 were needed to fix this. Hopefully #10 can find its way into a release soon. Thanks everyone for looking into this.

knaffles’s picture

Status: Needs review » Reviewed & tested by the community
knaffles’s picture

knaffles’s picture

Status: Reviewed & tested by the community » Fixed

This is fixed in release 8.x-1.6. The fix includes the patch in #10, as well as a check to ensure that blocks loaded by the loadEntityBlock method are not null before testing for access permissions.

Status: Fixed » Closed (fixed)

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