TB Mega Menu templates use the attributes key instead of the required #attributes in render arrays. Additionally, Drupal\Core\Template\Attribute objects are sometimes assigned directly to render array keys or treated like arrays, which breaks in Drupal 10 and 11.

These issues can cause white screens when rendering the menu in Twig, especially if the menu includes children.

Steps to reproduce

Create a twig template to style a view using TB Megamenu. The menu being styled should have children, You'll see a whitescreen referencing the twig template which is styling the output.

Proposed resolution

Replace usage of attributes with #attributes wherever they are intended for render arrays.
Replace usage of new Attribute() with plain arrays, or consistently use Attribute::addClass() etc. without treating the object like an array.

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

alanstanley created an issue. See original summary.

pablonicolas’s picture

I had a similar issue the other day, but not sure it was the same one you reported. This is part of the stracktrace:
InvalidArgumentException: "0" is an invalid render array key. Value should be an array, but got a string. in Drupal\Core\Render\Element::children() (line 97 of /web/core/lib/Drupal/Core/Render/Element.php).
Fixed by going to the module configuration page and saving it.

Not a definitive solution, but a quick fix to gain some time.

ravi kant’s picture

I have setup a new Project in Drupal 10.5.5 and try to create this issue but did not get any broken issue.

rbrownell’s picture

Assigned: Unassigned » rbrownell

rbrownell’s picture

Status: Active » Needs review

Thank you for reporting this issue.

I was unable to reproduce this issue with a fresh install of Drupal 11.3.2 and TB Mega Menu 3.0.0-alpha4 but I agree that there should be consistency in the implementation of the inclusion of attributes and classes.

I have created a patch for the 3.x-dev branch that modernizes the implementation of the theme.inc file by using the Attribute object's API instead of treating the object like an array.

Please review and let us know if this fixes the issue you're encountering.

rbrownell’s picture

Assigned: rbrownell » Unassigned
liam morland’s picture

Version: 3.0.0-alpha4 » 3.x-dev
pcfoster’s picture

Status: Needs review » Reviewed & tested by the community

May not address issue in #2, but changes in MR satisfy the issue described in this title.