How to modify a form to have some field surrounded by 'Details'?
I did it this way (thanks to @4K4 to put me on the right direction):

$form['fileDetails'] = array(
  '#type' =&gt; 'details',
  '#title' =&gt; $this-&gt;t('File'),
  '#weight' =&gt; 8,
);
$form['file']['#group'] = 'fileDetails';

$form['link']['widget']['0']['#type'] = 'details';


And I get this: