Project

General

Profile

Actions

Bug #104332

open

HMENU special with userfunc is broken for arbitrary links

Added by Xavier Perseguers 7 days ago. Updated 7 days ago.

Status:
Under Review
Priority:
Should have
Assignee:
-
Category:
Link Handling, Site Handling & Routing
Start date:
2024-07-08
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
12
PHP Version:
Tags:
Complexity:
Is Regression:
Yes
Sprint Focus:

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
        ];

Related issues 1 (0 open1 closed)

Follows TYPO3 Core - Task #97549: Deprecate $cObj->lastTypoLink* propertiesClosedBenni Mack2022-05-04

Actions
Actions #1

Updated by Xavier Perseguers 7 days ago

  • Due date set to 2022-05-05
  • Start date changed from 2024-07-08 to 2022-05-05
  • Follows Task #97549: Deprecate $cObj->lastTypoLink* properties added
Actions #2

Updated by Xavier Perseguers 7 days ago

  • Description updated (diff)
  • Due date deleted (2022-05-05)
  • Start date changed from 2022-05-05 to 2024-07-08
Actions #3

Updated by Gerrit Code Review 7 days ago

  • Status changed from New to Under Review

Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/85149

Actions

Also available in: Atom PDF