Rewrite Links Array to include Nesting 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:

&lt;ul&gt;
&lt;li&gt;English Link&lt;/li&gt;
&lt;li&gt;Japanese Link&lt;/li&gt;
&lt;li&gt;Spanish Link&lt;/li&gt;
&lt;/ul&gt;


I need:

&lt;ul&gt;
&lt;li&gt;English Link&lt;/li&gt;
&lt;ul&gt;
    &lt;li&gt;Japanese Link&lt;/li&gt;
    &lt;li&gt;Spanish Link&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;


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

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


How can I modify this array so that elements are nested in a ul under the first link?
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.