Bug #77296
closedTMENU - get the parentMenuArr in itemArrayProcFunc - broken
100%
Description
Hi there,
after upgrading from 6.2.25 to 7.6.9/7.6.10 our TMENU itemArrayProcFunc stopped working probably.
Not the function itself, but in it we used the parentMenuArr from the parentObj to determine the ITEM_STATE of the parent menu item, which this TMENU and items belongs to.
Given following abstract Menu TS CONF
HMENU { 1 = TMENU 1 {} 2 = TMENU 2 {} 3 = TMENU 3 = { itemArrayProcFunc = myUserFunc } }
For the 3rd level, we must do things based on the ITEM_STATE of the parentMenuItem from Level 2.
Not even that, also clearing the menuArr under some cirtumstances (flags in extension based fields) if parent state have specified flags etc.
To visualize this a little bit:
1.1 1.1.2.1 1.1.2.2 1.1.2.2.3.1 NO 1.1.2.2.3.2 NO 1.1.2.3 1.1.2.3.3.1 IF(1.1.2.3 ITEMSTATE === ACTIVE/CURRENT) THEN USERDEF1, OTHERWISE USERDEF2 1.1.2.3.3.1 IF(1.1.2.3 ITEMSTATE === ACTIVE/CURRENT) THEN USERDEF1, OTHERWISE USERDEF2
Okay, if you have to just render all Level2/3 Menu's in the same way for each parentLeven, than no user func is needed really ..
but if you want to render items for level based on the direct parent menu item item state, what than ?
I found no other solutions for that, so reimplementing the parentMenuArr behaviour was the only situation for our case ... are we so special ?
In the past (Typo 6.2.25) we had the following pseudo code in the userFunc to get the ITEM_STATE of the parent menuItem.
function($menuArr, $conf) { $parentItem = NULL; if (is_array($conf['parentObj']->parentMenuArr) && count($conf['parentObj']->parentMenuArr) > 0) { foreach($conf['parentObj']->parentMenuArr AS $menuItem) { if ($menuItem['uid'] === $conf['parentObj']->id) { $parentItem = $menuItem; break; // end the loop, we have what we wanted. } } } if (is_array($parentItem) && isset($parentItem['ITEM_STATE'])) { // loop through menuArr and do some special settings to the ITEM_STATE's and override virtually the titles } }
After debugging a lot, i'm ended up looking into the typo core and the functions for the menu rendering stuff.
See https://review.typo3.org/#/c/36584/5/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php LINE 458-460 in the old code.
In Typo 7.6.9 source and in current master, there was a lot changed in that class.
I think that 3 liner was dropped, because that property was not defined and even more, not returning an array every time. Maybe it was also removed, because the core itselfs do not need this -- but for userland functions this could be a usefull information.
I'm calling this a bug .. because removing this "public" property was not mentioned anywhere and broke's userland code.
Instead of simply readding the code, it should be done in proper way:
- not providing an public accessible property
- using setter/getter and returning always an array, an empty one if no parent level exists ( menu level 1 ).
- adding a function to just get the direct menuItem to prevent the need to loop through the parentMenuArray for each sublevel itemArrayProcFunc call, to optimize performance
Any suggestions welcome ;) I'm going to provide an patch for this bug, with the stated "improvements" instead of simply readding this.
Files
Updated by Gerrit Code Review over 8 years ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/49260
Updated by Gerrit Code Review over 8 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/49260
Updated by Gerrit Code Review over 8 years ago
Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/49260
Updated by Gerrit Code Review over 8 years ago
Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/49260
Updated by Stefan Bürk over 8 years ago
- File tmenu_test_0.0.1.zip tmenu_test_0.0.1.zip added
Added an testextension for reproducing the issue and for patch review.
The testextions works only for Typo 7.6 up to current master.
Provides three static templates with menus and itemArrayProcFunc functions:
- Testmenu - TopLevelCheck
- Testmenu - subMenu working in 6.2, broken in 7.6
- Testmenu - subMenu new getter
Template 1 and 2 works with and without the patch ( noting whenn the broken parentMenuArr is detected ),
with human readable messages.
The last one is to test the new getters provided by the patch.
The second one, subMenu working in 6.2, broken in 7.6 simulates
the real workcase we had, and what was broken in 7.6.
Theres a README.md in the extension.
Requirement for testing this is at least a two level pagetree with some pages,
Introduction/Bootstrap distribution works fine for it.
Just select the static template in the pagetemplate. Make sure cache are cleared
and page is not cached for testing purpose.
Hope the test extension helps.
Netherless, besides the issue, createing the testextension some caveats came in mind again.
In our workcase we are setting the ITEM_STATE of the parent/topLevel menu through the itemArrayProcFunc,
to rely on it in the second one. That means, all stats, not just the USERDEF ones.
This is done, because the ITEM_STATS are prozessed, after the subMenu's are prozessed.
Means:
Level1 - fetch pages Level1 - itemArrayProcFunc Level1 - iterate items Level2 - if Level1 has subItems, and a SubMenu is defined, create the subMenu and fetch the submenu pages Level2 - itemArrayProcFunc Level1 - generte/makeMenu ( prozess item states of the level 1 items ).
So, could be thought of if there could be a "prepared itemState" in the menuArr, before
handing it over as parentMenuArr to the submenu .. would be a bigger patch.
Maybe there are reasons why the processItemStats() is called so late after the the subMenus.
But this should be another discussion.
Note: The three static templates overrides page.5 to define the testmenu.
Updated by Gerrit Code Review over 8 years ago
Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/49260
Updated by Gerrit Code Review about 8 years ago
Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/49260
Updated by Gerrit Code Review about 8 years ago
Patch set 7 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/49260
Updated by Gerrit Code Review about 8 years ago
Patch set 8 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/49260
Updated by Gerrit Code Review about 8 years ago
Patch set 9 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/49260
Updated by Gerrit Code Review about 8 years ago
Patch set 10 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/49260
Updated by Gerrit Code Review about 8 years ago
Patch set 1 for branch TYPO3_7-6 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/50376
Updated by Gerrit Code Review about 8 years ago
Patch set 2 for branch TYPO3_7-6 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/50376
Updated by Stefan Bürk about 8 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 5b1dcea471108e90eed23999cbd339fe25045081.