Summary:
Version 2 breaks MenuManager with childrenof
Detailed Description:
Sorry if this has been covered before - I searched but couldn't see anything
relevant.
I've just upgraded from 1.12.2 to 2.2.16 which auto-updated fine.
On displaying my site the left nav menu is not displaying correctly. This is
called with
{menu loadprops=0 template='custom_left_menu' childrenof=$page_alias}
custom_left_menu uses $node->depth and $node->prevdepth to control the level
indentation. (It's a slightly modified version of the old "high_tour // ht" menu
template.)
After some digging it appears the problem is that $node->depth is being
calculated incorrectly. Instead of the expected value of '1' for the first item
in the childrenof list, MM is now returning '-1'.
You can see the issue if you print out $mnode after the FillNode() call on line
163 in MM::action.default.php.
This used to work in 1.12.2 but is broken in 2.2.16
Digging around in modules/MenuManager/action.default.php it seems that the
'depth' is calculated in FillNode() using the origdepth
$onenode->depth = count(explode('.', $content->Hierarchy())) - ($origdepth
- 1);
$origdepth is set in action.default.php line 159.
$prevdepth = $origdepth = $onenode->GetLevel() + 1;
On first pass this is calculating $prevdepth and $origdepth as 4 !
So it appears the issue is with lib/classes/get_level() which walks the tree
counting parents. For some reason, with childrenof, it is calculating too many,
so the subsequent calculation of depth (from prevdepth and origdepth) is wrong.
Has something changed in the structure of the node tree between 1.12 and 2.2
such that 'parent' counting is now failing?
Printing 'all levels' works fine - I'm only having problems with childrenof
Replacing L159 in action.default.php
$prevdepth = $origdepth = $onenode->GetLevel() + 1;
with
$prevdepth = $origdepth = count(explode('.', $onenode->getHierarchy()));
Fixes the problem (i.e. childrenof $node->depth is then correctly set to 1) and
my menu displays correctly. But I know not if that works in all cases (I only
tested 'childrenof').
I know you will suggest changing to use Navigator instead of MenuManager but
Navigator doesn't create $node->depth at all, and I'm not ready yet to change
all my templates just to use Navigator instead of MenuManager (by which I mean
there is no benefit if the site will look and perform just the same as now).
Thanks.