1

I'm attempting to modify the language switcher links in a block so that the items are properly nested per my site's menu structure.

Currently, it outputs:

<ul>
<li>English Link</li>
<li>Japanese Link</li>
<li>Spanish Link</li>
</ul>

I need:

<ul>
<li>English Link</li>
<ul>
    <li>Japanese Link</li>
    <li>Spanish Link</li>
</ul>
</ul>

The $build['content']['#links'] array contains:

array (size=4)
  'en' => 
    array (size=5)
      'url' => 
        object(Drupal\Core\Url)[14062]
        ...
    'ja' => 
        array (size=5)
          'url' => 
            object(Drupal\Core\Url)[14062]

How can I modify this array so that elements are nested in a ul under the first link?

1

In my experience, the structure you're looking for is created by the template layer. I would not recommend changing the link array directly. A good example template is core's stable theme's menu.html.twig. It uses a recursive twig macro to create nested lists.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.