[TYPO3-dev] itemArrayProcFunc inconsistent behaviour when no sub-pages - bug?
Peter
typo3 at peter-b.org
Mon Sep 24 18:00:01 CEST 2007
So, I've discovered as suspected that the problem is that without any
sub-pages, IFSUB is not automatically set in lib.mainNav.1 for the
relevant menu item - nor, having browsed the code, is there any apparent
sensible means of having the menu object do this to itself if the page
has no sub-pages but does get valid values from itemArrayProcFunc.
So, the solution I've used (in case anyone else ever runs into this!) is
to make this change in the code snippets from my previous mail:
1 = GMENU_LAYERS
1 {
expAll = 1
to:
1 = GMENU_LAYERS
1 {
itemArrayProcFunc = tx_myextension_myplugin->markMenuAsIFSUB
itemArrayProcFunc.insertMenuAtPID = 50
expAll = 1
and add the function to myextension_myplugin:
function markMenuAsIFSUB($menuArr,$conf) {
while(list($key,$value)=each($menuArr)) {
if ($menuArr[$key]['uid'] == $conf['insertMenuAtPID']) {
if ($conf['parentObj']->isItemState("CUR",$key)) {
$menuArr[$key]['ITEM_STATE'] = "CURIFSUB";
} else {
$menuArr[$key]['ITEM_STATE'] = "IFSUB";
}
}
}
return($menuArr);
}
And this does the trick....
Peter.
Peter wrote:
> T3:4.1.1 on Unix/PHP5
>
> Ok, a relatively common plugin task; produce a xMENU object that when
> rendered includes links to a single page containing a plugin to render
> different content based on showUid.
>
> In the case of one particular site, this must be done using
> itemArrayProcFunc, as the menu may or may not contain other items.
>
> My problem:
>
> If the page on which the menu is to be inserted contains no actual
> sub-pages, the menu does not appear.
>
> If I create a sub-page inside the page containing the plugin and clear
> the cache, the items generated by makeMenu appear.
>
> If I remove or hide the page without clearing the cache, the items
> generated by makeMenu remain. When the cache is cleared, the items
> generated by makeMenu disappear.
>
> Whenever the items are there, everything is working as expected; the
> menu is generated correctly, the links function as required. The key
> problem is that if the page containing the plugin has no subpages then
> the items returned by makeMenu are not rendered.
>
> Code:
>
> For the sake of simplicity, I've removed any TS relating to formatting:
>
> lib.mainNav = HMENU
> lib.mainNav {
> special = rootline
> 1 = GMENU_LAYERS
> 1 {
> expAll = 1
> [..]
> NO = 1
> NO {
> [..]
> 10 = TEXT
> 10 {
> text.field = title
> [..]
> }
> }
> [..]
> }
> 2 = GMENU_LAYERS
> 2 {
> itemArrayProcFunc = tx_myextension_myplugin->makeMenu
> [..]
> NO = 1
> NO {
> [..]
> 10 = TEXT
> 10 {
> text.field = title
> [..]
> }
> }
> [..]
> }
> }
>
> function makeMenu($menuArr,$conf) {
> $query = 'SELECT * FROM mytable';
> $res = mysql(TYPO3_db,$query);
> while ($row = mysql_fetch_assoc($res)) {
> $menuArr[] = $this->pi_getRecord('pages',50);
> }
> }
> return($menuArr);
> }
> }
>
> (yes, I know the above code will generate a menu entry pointing to page
> 50 for each row in the table "mytable" - this is the intended behaviour
> - I've stripped down the code for debugging purposes, normally the
> relevant "showUid" parameter would be added).
>
> I'm guessing this is linked to the item state of the parent menu item.
> If so, is it the responsibility of the function called by
> itemArrayProcFunc to control the state of that object, or should it
> handle itself properly when passed items through itemArrayProcFunc even
> if it has no subpages?
>
> If it is the responsibility of the called function, how do I do it?
>
> Peter.
>
>
More information about the TYPO3-dev
mailing list