Layout Builder crashes if an extra field renders menu items.

Created on 18 May 2019, over 5 years ago
Updated 31 May 2023, over 1 year ago

Problem/Motivation

When Layout Builder attempts to replace extra fields placeholders, it fails if the extra field includes menu link items. It seems in Drupal\Core\Menu\MenuLinkTree.php we are returning a "semi" renderable array of menu links. The values is_expanded is_collapsed and others are not renderable.

This issues appears when attempting to use Menu Item Extras (which provides an extra field called children that will contain all of the child links of the menu item being rendered). When Layout Builder attempts to replace the fields with placeholders Element::children fails because the menu links are not renderable.

Proposed resolution

For now, my solution was to check for the special extra field called children and just skip trying to replace the placeholders.

Remaining tasks

Definitely need to find a better way; this is a workaround.
Perhaps MenuLinkTree::buildItems needs to be changed and provide a fully compliant renderable array as expected by Element::children?

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Steps to Reproduce

  1. Install a fresh Drupal 8.7.1 site
  2. Enable Layout Builder and Menu Item Extras
  3. Enable Layout Builder for the Main Navigation menu
  4. Create a new Article node and add a menu link from the Node Edit form
  5. Navigate to the menu item in Drupal and attempt to edit the Layout for that menu link
πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States Justin Langley

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    I think the issue here is that menu item extras is declaring children as a valid extra field, but the output isn't a valid render array.

    I think it should use menu_item_extras_entity_view_alter to make sure that it is.

    Moving to the contrib issue queue.

Production build 0.71.5 2024