Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Recently I updated the radix theme from 4.5 to 4.6 and ended with the below error.
Twig\Error\RuntimeError: The merge filter only works with arrays or "Traversable", got "string" as second argument. in twig_array_merge() (line 41 of /themes/contrib/radix/src/components/nav/nav.twig).
{% set nav_link_classes = nav_link_classes|merge(item.url.options.attributes.class) %}
Comment | File | Size | Author |
---|---|---|---|
#4 | issue_after_upgrading_theme_to_4.6-3086685-004.patch | 807 bytes | stefan.korn |
Comments
Comment #2
stefan.kornComment #3
stefan.kornmaybe using this
instead of that
would fix this issue.
Will try it and provide a patch if it works.
Comment #4
stefan.kornI could reproduce this issue if I am injecting a class as string to attributes of link options.
But as per @larowlan the class should always be an array. So I suppose something (a contrib module?) is injecting the class wrongly.
@chandru225: Can you tell which class you like to inject there and from which module it does originate?
Anyway, I am proposing the following patch to avoid the behavior even if the class is not given as an array correctly. I think this might be valuable since this can otherwise lead to an WSOD which is not nice even if from a formal point of view the class is given in the wrong format from somewhere.
Comment #5
stefan.korn@chandru225: Maybe using menu_link_attributes module? - There is a problem with that module that would result in this error: https://github.com/yannickoo/menu_link_attributes/pull/61
Comment #6
criscomHi Stefan, your patch in #5 resovled this issue for us, using the menu_link_attributes module.
Sorry for opening a duplicate issue but the summary for this issue was not very specific.
Comment #7
chandru225 CreditAttribution: chandru225 as a volunteer and at TATA Consultancy Services for Johnson & Johnson commented@stefan.korn, yes I am using menu_link_attributes module
Comment #8
stefan.kornOk, to summarize this:
It seems that menu_link_attributes module is providing the class information in wrong format and this leads to WSOD here. With the patch provided we could avoid WSOD even if the class information is provided in wrong format. So maybe patch makes sense, although from a strict point of view the fault is on menu_link_attributes side.
Comment #9
shadcn CreditAttribution: shadcn at Chapter Three commentedis iterable
Nice 👍Tested. I'll commit this.
Comment #11
shadcn CreditAttribution: shadcn at Chapter Three commentedComment #13
yannickooBTW this will be fixed in Menu Link Attributes so at some points the "workaround" could be removed: #3199777: Make "class" attribute an array