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
Comments
Comment #2
pablonicolasI 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.
Comment #3
ravi kant commentedI have setup a new Project in Drupal 10.5.5 and try to create this issue but did not get any broken issue.
Comment #4
rbrownellComment #6
rbrownellThank 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.
Comment #7
rbrownellComment #8
liam morlandComment #9
pcfoster commentedMay not address issue in #2, but changes in MR satisfy the issue described in this title.