Tokens in subtree links are not replaced

Created on 10 May 2024, 9 months ago

Problem/Motivation

Tokens in subtree links are not replaced.

Steps to reproduce

  1. Go to /admin/structure/menu/manage/main and create a menu item.
  2. Create a second menu item as follows:
    • Set the Link field to a path that contains a token.
    • Check the box for "Use tokens in title and in path" and configure context.
    • Set the first menu item as this item's parent.
  3. Rebuild cache.
  4. Refresh /admin/structure/menu/manage/main.
  5. Inspect the child link.

Expected result: The token is replaced in the child link's URL.
Actual result: The token is not replaced.

Proposed resolution

The problem is in \Drupal\menu_token\Service\MenuLinkTreeMenuToken::replaceLinkUrls. This method loops through the menu tree, but does not check each link's subtree value; thus, only top-level links are replaced. This can be solved by recursing through the subtree (if it is not empty).

πŸ› Bug report
Status

Needs review

Version

9.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States muriqui

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024