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) %}

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chandru225 created an issue. See original summary.

stefan.korn’s picture

stefan.korn’s picture

maybe using this

{% if item.url.options.attributes.class is iterable %}
          {% set nav_link_classes = nav_link_classes|merge(item.url.options.attributes.class) %}
        {% endif %}

instead of that

{% if item.url.options.attributes.class %}
          {% set nav_link_classes = nav_link_classes|merge(item.url.options.attributes.class) %}
        {% endif %}

would fix this issue.

Will try it and provide a patch if it works.

stefan.korn’s picture

I 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.

stefan.korn’s picture

@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

criscom’s picture

Hi 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.

chandru225’s picture

@stefan.korn, yes I am using menu_link_attributes module

stefan.korn’s picture

Ok, 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.

shadcn’s picture

Status: Needs review » Reviewed & tested by the community

is iterable Nice 👍

Tested. I'll commit this.

shadcn’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

yannickoo’s picture

BTW this will be fixed in Menu Link Attributes so at some points the "workaround" could be removed: #3199777: Make "class" attribute an array