Alter the wrapper of radios buttons in a custom module In a custom module, I have created a custom form. In this form, I need to alter the markup of the radio buttons wrapper and add a new attribute.
After reading many posts and testing, I can alter all the form elements (form-item, first fieldset...) except this wrapper.

This is the markup I am outputting.

&lt;fieldset ...&gt;
  &lt;legend&gt;Mylegend&lt;/legend&gt;
    &lt;div class="fieldset-wrapper"&gt;
      &lt;div id="edit-myfield"&gt; &lt;!-- &lt; I need to alter the attributes of this div --&gt;
        &lt;div class="form-item js-form-item form-type-radio js-form-type-radio..."&gt;
    ...
        &lt;/div&gt;
        &lt;div class="form-item js-form-item form-type-radio js-form-type-radio..."&gt;
          ...
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/fieldset&gt;


I see that the related system template is radios.html.twig. I tried to copy and paste this template in the templates directory of my module without success. I tried to use theme =&gt; 'my custom theme' in the definition of my field. I tried to use a preprocess function in my module.

What is the simpler method to alter this wrapper?
You can do this directly in the form.

Add this to the radios element:

'#attributes' =&gt; [
  'attribute_name' = 'attribute_value'
],