Add possibility to placeholder menu renders

Created on 14 March 2024, 10 months ago

Problem/Motivation

On one of my sites, I encountered an issue where all pages became uncacheable because an editor added a menu item referencing a non-existing (or maybe existing, but deleted) node. The problem is that Drupal\Core\Access\AccessManager::checkNamedRoute() marks the response as uncacheable if a ParamNotConvertedException is thrown:

Uncacheable because conversion of the parameter may not have been possible due to dynamic circumstances.

Steps to reproduce

  1. Add a menu link where the link is entity:node/<nid>, and is a non-existing node id.
  2. Render the menu using the drupal_menu Twig function
  3. Pages displaying the menu will have the x-drupal-dynamic-cache: UNCACHEABLE response header.

Proposed resolution

Add a new placeholder parameter to drupal_menu, which will make sure the menu is placeholdered, fixing dynamic page cache. More information about placeholdering can be found in this blog post.

Feature request
Status

Needs review

Version

3.3

Component

Code

Created by

🇧🇪Belgium dieterholvoet Brussels

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