Bug #104332
closedHMENU special with userfunc is broken for arbitrary links
100%
Description
TypoScript¶
lib.menu.breadcrumb = HMENU lib.menu.breadcrumb { special = userfunction special.userFunc = VENDOR\EXTENSION\TypoScript\BreadcrumbMenu->makeMenuArray 1 = TMENU 1.NO.wrapItemAndSub = <li> | </li> }
Add this TS rendering somewhere on your page, such as with
page.99 < lib.menu.breadcrumb
VENDOR\EXTENSION\TypoScript\BreadcrumbMenu¶
class BreadcrumbMenu { public function makeMenuArray(string $content, array $conf): array { $data = []; $data[] = [ 'title' => 'Google', '_OVERRIDE_HREF' => 'https://www.google.com/', '_OVERRIDE_TARGET' => '', 'ITEM_STATE' => 'ACT', ]; return $data; } }
Behaviour in TYPO3 v11¶
- The link is working
Behaviour in TYPO3 v12¶
- The link is not generated, menu is generated with the text "Google", but no link associated, as with doNotLinkIt
.
Reason¶
In commit 7be9318b2b associated to #97549, method AbstractMenuContentObject->menuTypoLink()
switched from using ->typolink()
to using ->createLink()
This is called within method AbstractMenuContentObject->link()
when initializing $linkResult
. Problem: the custom menu array leads to an exception as TYPO3 tries to link to a page which is not defined (0), thus no link can be created. The exception is catched in method link()
instead of just going further and using the value of `_OVERRIDE_HREF` that is provided and would be used right after the link generation if there weren't any exception.
Trick to make it work with that new behaviour¶
That's really nasty but if we enhance what we return in our custom menu, the exception is prevented and this "works again" in TYPO3 v12, although this is unclean:
$data[] = [ 'title' => 'Google', '_OVERRIDE_HREF' => 'https://www.google.com/', '_OVERRIDE_TARGET' => '', 'ITEM_STATE' => 'ACT', // Dumb properties below to make TYPO3 v12 happy: 'uid' => 1, // must be some public page, here e.g., the website root page 'doktype' => 0, // to prevent a PHP warning 'l10n_parent' => 0, // to prevent a PHP warning ];