Bug #104332
Updated by Xavier Perseguers 5 months ago
h2. TypoScript <pre> lib.menu.breadcrumb = HMENU lib.menu.breadcrumb { special = userfunction special.userFunc = VENDOR\EXTENSION\TypoScript\BreadcrumbMenu->makeMenuArray 1 = TMENU 1.NO.wrapItemAndSub = <li> | </li> } </pre> Add this TS rendering somewhere on your page, such as with <pre> page.99 < lib.menu.breadcrumb </pre> h2. VENDOR\EXTENSION\TypoScript\BreadcrumbMenu <pre> 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; } } </pre> h2. Behaviour in TYPO3 v11 - The link is working h2. Behaviour in TYPO3 v12 - The link is not generated, menu is generated with the text "Google", but no link associated, as with @doNotLinkIt@. h2. Reason In commit 7be9318b2b associated to #97549, method @AbstractMenuContentObject->menuTypoLink()@ @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. h2. 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: <pre> $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 ]; </pre>